diff options
author | Daniel Pittman <daniel@puppetlabs.com> | 2011-03-24 13:10:27 -0700 |
---|---|---|
committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-04 10:19:33 -0700 |
commit | 5bba1a26140cd3326739b00c2d60dff9321d4044 (patch) | |
tree | e0fb09eca95550918dd504b6d7a9c6949b905406 /lib/puppet/string/action_builder.rb | |
parent | 1400fec62e4e692badc5b68eb7d6d947997d7204 (diff) | |
download | puppet-5bba1a26140cd3326739b00c2d60dff9321d4044.tar.gz puppet-5bba1a26140cd3326739b00c2d60dff9321d4044.tar.xz puppet-5bba1a26140cd3326739b00c2d60dff9321d4044.zip |
(#6749) Implement support for options on strings and actions.
We want to support both strings and actions specifying options, to support
generic wrappers that present strings to the user across multiple distinct
front-ends.
At the moment we focus on implementation of a generic CLI providing full
control to all the strings, but we aim to support other programmatic
interfaces including Ruby and RPC invocation as part of the overall change.
We also detect, at the time they are declared, duplicate options. They are
reported, like any duplicate, with an error thrown. Specifically:
It is illegal to declare a duplicate option in the same scope, such as within
the same string, or within the same action. This is unchanged.
It is illegal to declare an option in an action that duplicates an option in
the string, or vice-versa. This is reported when the duplicate is declared,
so may report on either the string or action depending on sequence.
It remains legal to duplicate the same option across multiple actions, with
different meanings. There is no conflict, as the same option can't be passed
to both simultaneously.
Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
Diffstat (limited to 'lib/puppet/string/action_builder.rb')
-rw-r--r-- | lib/puppet/string/action_builder.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/puppet/string/action_builder.rb b/lib/puppet/string/action_builder.rb index b3db51104..fb2a749ae 100644 --- a/lib/puppet/string/action_builder.rb +++ b/lib/puppet/string/action_builder.rb @@ -5,10 +5,8 @@ class Puppet::String::ActionBuilder attr_reader :action def self.build(string, name, &block) - name = name.to_s - raise "Action '#{name}' must specify a block" unless block - builder = new(string, name, &block) - builder.action + raise "Action #{name.inspect} must specify a block" unless block + new(string, name, &block).action end def initialize(string, name, &block) @@ -24,4 +22,9 @@ class Puppet::String::ActionBuilder raise "Invoke called on an ActionBuilder with no corresponding Action" unless @action @action.invoke = block end + + def option(name, attrs = {}, &block) + option = Puppet::String::OptionBuilder.build(@action, name, attrs, &block) + @action.add_option(option) + end end |