Enable verbose mode when PRODUCER_VERBOSE is set
This commit is contained in:
parent
cd389a3209
commit
bd754f2bf6
@ -41,3 +41,8 @@ Feature: CLI verbose option
|
|||||||
"""
|
"""
|
||||||
When I successfully execute the recipe with option -v
|
When I successfully execute the recipe with option -v
|
||||||
Then the output must match /action: .{,70}$/
|
Then the output must match /action: .{,70}$/
|
||||||
|
|
||||||
|
Scenario: enables verbose mode from the environment
|
||||||
|
Given I set the environment variable "PRODUCER_VERBOSE"
|
||||||
|
When I successfully execute the recipe
|
||||||
|
Then the output must contain "Task"
|
||||||
|
3
features/steps/environment_steps.rb
Normal file
3
features/steps/environment_steps.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Given /^I set the environment variable "([^"]+)"$/ do |variable|
|
||||||
|
set_env variable, 'yes'
|
||||||
|
end
|
@ -10,9 +10,13 @@ module Producer
|
|||||||
|
|
||||||
ARGUMENTS_SEPARATOR = '--'.freeze
|
ARGUMENTS_SEPARATOR = '--'.freeze
|
||||||
|
|
||||||
|
ENV_VERBOSE_KEY = 'PRODUCER_VERBOSE'.freeze
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def run!(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr)
|
def run!(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr)
|
||||||
cli = new(arguments, stdin: stdin, stdout: stdout, stderr: stderr)
|
cli = new(
|
||||||
|
arguments, ENV, stdin: stdin, stdout: stdout, stderr: stderr
|
||||||
|
)
|
||||||
begin
|
begin
|
||||||
cli.parse_arguments!
|
cli.parse_arguments!
|
||||||
cli.run
|
cli.run
|
||||||
@ -32,12 +36,14 @@ module Producer
|
|||||||
|
|
||||||
attr_reader :arguments, :stdin, :stdout, :stderr, :env
|
attr_reader :arguments, :stdin, :stdout, :stderr, :env
|
||||||
|
|
||||||
def initialize(args, stdin: $stdin, stdout: $stdout, stderr: $stderr)
|
def initialize(args, environment, stdin: $stdin, stdout: $stdout, stderr: $stderr)
|
||||||
@arguments = args
|
@arguments = args
|
||||||
@stdin = stdin
|
@stdin = stdin
|
||||||
@stdout = stdout
|
@stdout = stdout
|
||||||
@stderr = stderr
|
@stderr = stderr
|
||||||
@env = build_env
|
@env = build_env
|
||||||
|
|
||||||
|
configure_environment! environment
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_arguments!
|
def parse_arguments!
|
||||||
@ -65,6 +71,10 @@ module Producer
|
|||||||
Env.new(input: @stdin, output: @stdout, error_output: @stderr)
|
Env.new(input: @stdin, output: @stdout, error_output: @stderr)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def configure_environment!(environment)
|
||||||
|
@env.verbose = true if environment.key? ENV_VERBOSE_KEY
|
||||||
|
end
|
||||||
|
|
||||||
def split_arguments_lists(arguments)
|
def split_arguments_lists(arguments)
|
||||||
arguments
|
arguments
|
||||||
.chunk { |e| e == ARGUMENTS_SEPARATOR }
|
.chunk { |e| e == ARGUMENTS_SEPARATOR }
|
||||||
|
@ -8,15 +8,16 @@ module Producer::Core
|
|||||||
let(:options) { [] }
|
let(:options) { [] }
|
||||||
let(:recipe_file) { fixture_path_for 'recipes/some_recipe.rb' }
|
let(:recipe_file) { fixture_path_for 'recipes/some_recipe.rb' }
|
||||||
let(:arguments) { [*options, recipe_file] }
|
let(:arguments) { [*options, recipe_file] }
|
||||||
|
let(:environment) { {} }
|
||||||
|
|
||||||
subject(:cli) { described_class.new(arguments) }
|
subject(:cli) { described_class.new(arguments, environment) }
|
||||||
|
|
||||||
describe '.run!' do
|
describe '.run!' do
|
||||||
subject(:run!) { described_class.run! arguments }
|
subject(:run!) { described_class.run! arguments }
|
||||||
|
|
||||||
it 'builds a new CLI instance with given arguments' do
|
it 'builds a new CLI instance with given arguments and environment' do
|
||||||
expect(described_class)
|
expect(described_class)
|
||||||
.to receive(:new).with(arguments, anything).and_call_original
|
.to receive(:new).with(arguments, ENV, anything).and_call_original
|
||||||
run!
|
run!
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -75,6 +76,14 @@ module Producer::Core
|
|||||||
it 'assigns CLI stderr as the env error output' do
|
it 'assigns CLI stderr as the env error output' do
|
||||||
expect(cli.env.error_output).to be cli.stderr
|
expect(cli.env.error_output).to be cli.stderr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when PRODUCER_VERBOSE environment variable is set' do
|
||||||
|
before { environment['PRODUCER_VERBOSE'] = 'yes' }
|
||||||
|
|
||||||
|
it 'enables env verbose mode' do
|
||||||
|
expect(cli.env).to be_verbose
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#parse_arguments!' do
|
describe '#parse_arguments!' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user