diff --git a/features/cli/debug.feature b/features/cli/debug.feature index f22eee6..acd23ae 100644 --- a/features/cli/debug.feature +++ b/features/cli/debug.feature @@ -11,3 +11,9 @@ Feature: CLI debug option Then the output must contain "producer" And the output must contain "net-ssh" And the output must contain ruby lib directory + + Scenario: enables debug mode from the environment + Given a recipe with an error + And I set the environment variable "PRODUCER_DEBUG" + When I execute the recipe + Then the output must contain "producer" diff --git a/lib/producer/core/cli.rb b/lib/producer/core/cli.rb index b64f25b..0519099 100644 --- a/lib/producer/core/cli.rb +++ b/lib/producer/core/cli.rb @@ -11,6 +11,7 @@ module Producer ARGUMENTS_SEPARATOR = '--'.freeze ENV_VERBOSE_KEY = 'PRODUCER_VERBOSE'.freeze + ENV_DEBUG_KEY = 'PRODUCER_DEBUG'.freeze class << self def run!(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr) @@ -73,6 +74,7 @@ module Producer def configure_environment!(environment) @env.verbose = true if environment.key? ENV_VERBOSE_KEY + @env.debug = true if environment.key? ENV_DEBUG_KEY end def split_arguments_lists(arguments) diff --git a/spec/producer/core/cli_spec.rb b/spec/producer/core/cli_spec.rb index ee55b48..fa970dc 100644 --- a/spec/producer/core/cli_spec.rb +++ b/spec/producer/core/cli_spec.rb @@ -84,6 +84,14 @@ module Producer::Core expect(cli.env).to be_verbose end end + + context 'when PRODUCER_DEBUG environment variable is set' do + before { environment['PRODUCER_DEBUG'] = 'yes' } + + it 'enables env debug mode' do + expect(cli.env).to be_debug + end + end end describe '#parse_arguments!' do