diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-07-22 14:11:35 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-07-22 16:26:20 -0700 |
| commit | 6bec2df0860b71730b99ddd9f1764aa2ce0dc960 (patch) | |
| tree | ca48a127207e256acb7f366817ceb8babbc3b338 /spec/unit | |
| parent | feec7b3df713569f76b93ae8cef882e9ddc1bf35 (diff) | |
| download | puppet-6bec2df0860b71730b99ddd9f1764aa2ce0dc960.tar.gz puppet-6bec2df0860b71730b99ddd9f1764aa2ce0dc960.tar.xz puppet-6bec2df0860b71730b99ddd9f1764aa2ce0dc960.zip | |
(#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 <pieter@puppetlabs.com>
Diffstat (limited to 'spec/unit')
| -rwxr-xr-x | spec/unit/interface/action_spec.rb | 26 |
1 files changed, 20 insertions, 6 deletions
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 |
