Enable dry run mode when PRODUCER_DRYRUN is set

This commit is contained in:
Thibault Jouan 2015-04-06 13:53:29 +00:00
parent 2b0e62be26
commit 658e333420
3 changed files with 17 additions and 2 deletions

View File

@ -15,3 +15,8 @@ Feature: CLI dry run option
Scenario: prints a warning before any output Scenario: prints a warning before any output
When I successfully execute the recipe with option -n When I successfully execute the recipe with option -n
Then the output must match /\AWarning: running in dry run mode, actions will NOT be applied/ Then the output must match /\AWarning: running in dry run mode, actions will NOT be applied/
Scenario: enables dry run mode from the environment
Given I set the environment variable "PRODUCER_DRYRUN"
When I successfully execute the recipe
Then the output must contain "running in dry run"

View File

@ -12,6 +12,7 @@ module Producer
ENV_VERBOSE_KEY = 'PRODUCER_VERBOSE'.freeze ENV_VERBOSE_KEY = 'PRODUCER_VERBOSE'.freeze
ENV_DEBUG_KEY = 'PRODUCER_DEBUG'.freeze ENV_DEBUG_KEY = 'PRODUCER_DEBUG'.freeze
ENV_DRYRUN_KEY = 'PRODUCER_DRYRUN'.freeze
class << self class << self
def run!(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr) def run!(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr)
@ -75,6 +76,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 @env.debug = true if environment.key? ENV_DEBUG_KEY
@env.dry_run = true if environment.key? ENV_DRYRUN_KEY
end end
def split_arguments_lists(arguments) def split_arguments_lists(arguments)

View File

@ -92,6 +92,14 @@ module Producer::Core
expect(cli.env).to be_debug expect(cli.env).to be_debug
end end
end end
context 'when PRODUCER_DRYRUN environment variable is set' do
before { environment['PRODUCER_DRYRUN'] = 'yes' }
it 'enables env dry run mode' do
expect(cli.env).to be_dry_run
end
end
end end
describe '#parse_arguments!' do describe '#parse_arguments!' do