From 6bec2df0860b71730b99ddd9f1764aa2ce0dc960 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Fri, 22 Jul 2011 14:11:35 -0700 Subject: (#8561) Use canonical names for options to actions. When we invoke an action, we parse a set of options. These have a canonical name, and optionally a set of aliases. For example, :bar might have :b as an alias to allow a short name to be given. Previously we would just pass this on as received; if you passed :bar you got :bar, and if you passed :b you got :b. This works, but means that every action has to write the same code to extract the appropriate version of an option from whatever set of aliases might be passed. Now, instead, we centralize that and always pass options as their canonical name to the action code. This makes it simpler to work with. (This happens before any validation, or other user-supplied, code to simplify everything that handles options.) Reviewed-By: Pieter van de Bruggen --- spec/unit/interface/action_spec.rb | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'spec/unit') diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb index d71a7d000..848a44bba 100755 --- a/spec/unit/interface/action_spec.rb +++ b/spec/unit/interface/action_spec.rb @@ -171,14 +171,28 @@ describe Puppet::Interface::Action do face.get_action(:foo).options.should =~ [:bar] end - it "should only list options and not aliases" do - face = Puppet::Interface.new(:action_level_options, '0.0.1') do - action :foo do - when_invoked do |options| true end - option "--bar", "-b", "--foo-bar" + describe "option aliases" do + let :option do action.get_option :bar end + let :action do face.get_action :foo end + let :face do + Puppet::Interface.new(:action_level_options, '0.0.1') do + action :foo do + when_invoked do |options| options end + option "--bar", "--foo", "-b" + end + end + end + + it "should only list options and not aliases" do + action.options.should =~ [:bar] + end + + it "should use the canonical option name when passed aliases" do + name = option.name + option.aliases.each do |input| + face.foo(input => 1).should == { name => 1 } end end - face.get_action(:foo).options.should =~ [:bar] end describe "with both face and action options" do -- cgit