Remove host argument:

Currently the idea is to later implement a -h (or -t) option to the
command, and/or a `target' recipe keyword. Another option might be to
use the target/host key when the key/value registry will be implemented
and made available to the recipe and task DSLs.
This commit is contained in:
Thibault Jouan 2013-07-31 22:33:09 +00:00
parent 2acb57254f
commit 0aa043b61a
4 changed files with 21 additions and 14 deletions

View File

@ -5,5 +5,5 @@ Feature: CLI usage
Then the exit status must be 64 Then the exit status must be 64
And the output must contain exactly: And the output must contain exactly:
""" """
Usage: producer host recipe_file Usage: producer recipe_file
""" """

View File

@ -3,5 +3,5 @@ Given(/^a recipe with:$/) do |recipe_body|
end end
When(/^I execute the recipe$/) do When(/^I execute the recipe$/) do
run_simple('producer localhost recipe.rb', false) run_simple('producer recipe.rb', false)
end end

View File

@ -3,7 +3,7 @@ module Producer
class CLI class CLI
attr_reader :arguments attr_reader :arguments
USAGE = "Usage: #{File.basename $0} host recipe_file" USAGE = "Usage: #{File.basename $0} recipe_file"
def initialize(arguments, stdout = $stdout) def initialize(arguments, stdout = $stdout)
@stdout = stdout @stdout = stdout
@ -16,11 +16,11 @@ module Producer
end end
def check_arguments! def check_arguments!
print_usage_and_exit(64) unless @arguments.length == 2 print_usage_and_exit(64) unless @arguments.length == 1
end end
def evaluate_recipe_file def evaluate_recipe_file
recipe = Recipe.from_file(@arguments[1]) recipe = Recipe.from_file(@arguments.first)
env = Env.new(recipe) env = Env.new(recipe)
begin begin
recipe.evaluate env recipe.evaluate env

View File

@ -4,8 +4,9 @@ module Producer::Core
describe CLI do describe CLI do
include FixturesHelpers include FixturesHelpers
let(:arguments) { ['host', fixture_path_for('recipes/empty.rb')] } let(:recipe_file) { fixture_path_for('recipes/empty.rb') }
subject(:cli) { CLI.new(arguments) } let(:arguments) { [recipe_file] }
subject(:cli) { CLI.new(arguments) }
describe '#initialize' do describe '#initialize' do
it 'assigns the arguments' do it 'assigns the arguments' do
@ -26,8 +27,14 @@ module Producer::Core
end end
describe '#check_arguments!' do describe '#check_arguments!' do
context 'when an argument is missing' do context 'when recipe argument is provided' do
let(:arguments) { %w{host} } it 'does not raise any error' do
expect { cli.check_arguments! }.to_not raise_error
end
end
context 'when recipe argument is missing' do
let(:arguments) { [] }
let(:stdout) { StringIO.new } let(:stdout) { StringIO.new }
subject(:cli) { CLI.new(arguments, stdout) } subject(:cli) { CLI.new(arguments, stdout) }
@ -50,7 +57,7 @@ module Producer::Core
describe '#evaluate_recipe_file' do describe '#evaluate_recipe_file' do
it 'builds a recipe' do it 'builds a recipe' do
expect(Recipe) expect(Recipe)
.to receive(:from_file).with(arguments[1]).and_call_original .to receive(:from_file).with(recipe_file).and_call_original
cli.evaluate_recipe_file cli.evaluate_recipe_file
end end
@ -71,9 +78,9 @@ module Producer::Core
end end
context 'error during recipe evaluation' do context 'error during recipe evaluation' do
let(:arguments) { ['host', fixture_path_for('recipes/invalid.rb')] } let(:recipe_file) { fixture_path_for('recipes/invalid.rb') }
let(:stdout) { StringIO.new } let(:stdout) { StringIO.new }
subject(:cli) { CLI.new(arguments, stdout) } subject(:cli) { CLI.new(arguments, stdout) }
it 'exits with a return status of 70' do it 'exits with a return status of 70' do
expect { cli.evaluate_recipe_file } expect { cli.evaluate_recipe_file }
@ -89,7 +96,7 @@ module Producer::Core
end end
expect(stdout.string).to match(/ expect(stdout.string).to match(/
\A \A
#{arguments[1]}:4: #{recipe_file}:4:
.+ .+
invalid\srecipe\skeyword\s`invalid_keyword' invalid\srecipe\skeyword\s`invalid_keyword'
/x) /x)