Enable debug mode when PRODUCER_DEBUG is set

This commit is contained in:
Thibault Jouan 2015-04-06 13:49:44 +00:00
parent bd754f2bf6
commit 2b0e62be26
3 changed files with 16 additions and 0 deletions

View File

@ -11,3 +11,9 @@ Feature: CLI debug option
Then the output must contain "producer" Then the output must contain "producer"
And the output must contain "net-ssh" And the output must contain "net-ssh"
And the output must contain ruby lib directory 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"

View File

@ -11,6 +11,7 @@ module Producer
ARGUMENTS_SEPARATOR = '--'.freeze ARGUMENTS_SEPARATOR = '--'.freeze
ENV_VERBOSE_KEY = 'PRODUCER_VERBOSE'.freeze ENV_VERBOSE_KEY = 'PRODUCER_VERBOSE'.freeze
ENV_DEBUG_KEY = 'PRODUCER_DEBUG'.freeze
class << self class << self
def run!(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr) def run!(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr)
@ -73,6 +74,7 @@ module Producer
def configure_environment!(environment) def configure_environment!(environment)
@env.verbose = true if environment.key? ENV_VERBOSE_KEY @env.verbose = true if environment.key? ENV_VERBOSE_KEY
@env.debug = true if environment.key? ENV_DEBUG_KEY
end end
def split_arguments_lists(arguments) def split_arguments_lists(arguments)

View File

@ -84,6 +84,14 @@ module Producer::Core
expect(cli.env).to be_verbose expect(cli.env).to be_verbose
end end
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 end
describe '#parse_arguments!' do describe '#parse_arguments!' do