summaryrefslogtreecommitdiffstats
path: root/lib/puppet/interface/action_builder.rb
diff options
context:
space:
mode:
authorMax Martin <max@puppetlabs.com>2011-04-13 17:30:44 -0700
committerMax Martin <max@puppetlabs.com>2011-04-13 17:30:44 -0700
commit3dde838ac992571e13262ea29ba3a0eb8152e753 (patch)
tree90520cf62bfa2f1bb9c992bbfe1bc47ae10471f2 /lib/puppet/interface/action_builder.rb
parentfe45c2417af580597cd39adec96a30a05a7cd66a (diff)
parent3ab44c7ce01ab86a995deb66228f5be95239c92a (diff)
downloadpuppet-3dde838ac992571e13262ea29ba3a0eb8152e753.tar.gz
puppet-3dde838ac992571e13262ea29ba3a0eb8152e753.tar.xz
puppet-3dde838ac992571e13262ea29ba3a0eb8152e753.zip
Merge branch 'next'
* next: (204 commits) Revert "(#6928) Removed --ignoreimport" Updated CHANGELOG for 2.6.8rc1 (#6928) Removed --ignoreimport (#6928) Remove --parseonly (#6928) Add a Parser face with Validate action (#6830) Fix sha1 to digest/sha1 require issue for Ruby 1.9 (#6830) Fix UTF-8 encoding issue for Ruby 1.9 (#6830) Fix string method sub call on a symbol for Ruby 1.9 (#2331) Remove darwinports pkg provider, replace with rewritten macports provider (#7059) handle inherited action binding scope maint: ensure we handle '-foo=' options correctly in faces. (#2150) Fix File const lookup when configuring routes Fixed #7082 - Added system support for groups maint: install erb templates under lib/ maint: clean up the spec test headers in bulk. (#7056) Use 'face' rather than 'faces' in the production code. maint: eliminate deprecated since 2008 code from Puppet. (#6117) Add POST support to indirector requests (#6962) Move option handling into #parse_options, not #preinit. maint: whitespace cleanup for puppet/util/command_line. ...
Diffstat (limited to 'lib/puppet/interface/action_builder.rb')
-rw-r--r--lib/puppet/interface/action_builder.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/puppet/interface/action_builder.rb b/lib/puppet/interface/action_builder.rb
new file mode 100644
index 000000000..34bb3fa44
--- /dev/null
+++ b/lib/puppet/interface/action_builder.rb
@@ -0,0 +1,35 @@
+require 'puppet/interface'
+require 'puppet/interface/action'
+
+class Puppet::Interface::ActionBuilder
+ attr_reader :action
+
+ def self.build(face, name, &block)
+ raise "Action #{name.inspect} must specify a block" unless block
+ new(face, name, &block).action
+ end
+
+ private
+ def initialize(face, name, &block)
+ @face = face
+ @action = Puppet::Interface::Action.new(face, name)
+ instance_eval(&block)
+ end
+
+ # Ideally the method we're defining here would be added to the action, and a
+ # method on the face would defer to it, but we can't get scope correct, so
+ # we stick with this. --daniel 2011-03-24
+ def when_invoked(&block)
+ raise "when_invoked on an ActionBuilder with no corresponding Action" unless @action
+ @action.when_invoked = block
+ end
+
+ def option(*declaration, &block)
+ option = Puppet::Interface::OptionBuilder.build(@action, *declaration, &block)
+ @action.add_option(option)
+ end
+
+ def summary(text)
+ @action.summary = text
+ end
+end