diff --git a/features/cli/dry_run.feature b/features/cli/dry_run.feature index e8e7b90..3eb72bf 100644 --- a/features/cli/dry_run.feature +++ b/features/cli/dry_run.feature @@ -15,3 +15,8 @@ Feature: CLI dry run option Scenario: prints a warning before any output 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/ + + 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" diff --git a/lib/producer/core/cli.rb b/lib/producer/core/cli.rb index 0519099..c170de0 100644 --- a/lib/producer/core/cli.rb +++ b/lib/producer/core/cli.rb @@ -12,6 +12,7 @@ module Producer ENV_VERBOSE_KEY = 'PRODUCER_VERBOSE'.freeze ENV_DEBUG_KEY = 'PRODUCER_DEBUG'.freeze + ENV_DRYRUN_KEY = 'PRODUCER_DRYRUN'.freeze class << self def run!(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr) @@ -73,8 +74,9 @@ module Producer end def configure_environment!(environment) - @env.verbose = true if environment.key? ENV_VERBOSE_KEY - @env.debug = true if environment.key? ENV_DEBUG_KEY + @env.verbose = true if environment.key? ENV_VERBOSE_KEY + @env.debug = true if environment.key? ENV_DEBUG_KEY + @env.dry_run = true if environment.key? ENV_DRYRUN_KEY end def split_arguments_lists(arguments) diff --git a/spec/producer/core/cli_spec.rb b/spec/producer/core/cli_spec.rb index fa970dc..1897a24 100644 --- a/spec/producer/core/cli_spec.rb +++ b/spec/producer/core/cli_spec.rb @@ -92,6 +92,14 @@ module Producer::Core expect(cli.env).to be_debug 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 describe '#parse_arguments!' do