diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-03-26 00:12:17 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-03-28 10:45:34 -0700 |
| commit | b859baa04737644e40002f511c5941d002a956e3 (patch) | |
| tree | f8f4d581c3b0445df836d5e55945f62547239598 /lib/puppet/application/string.rb | |
| parent | 88aeb04a50d8997b5e1e0ed7a5a2239508b174ee (diff) | |
| download | puppet-b859baa04737644e40002f511c5941d002a956e3.tar.gz puppet-b859baa04737644e40002f511c5941d002a956e3.tar.xz puppet-b859baa04737644e40002f511c5941d002a956e3.zip | |
MAINT: the API is officially named "string" as of this moment.
Now that we have settled on the final public name for the API,
"Puppet::String", mass-rename and mass-edit all the files to follow.
Reviewed-By: Randall Hansen <randall@puppetlabs.com>
Diffstat (limited to 'lib/puppet/application/string.rb')
| -rw-r--r-- | lib/puppet/application/string.rb | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/lib/puppet/application/string.rb b/lib/puppet/application/string.rb new file mode 100644 index 000000000..aa369e669 --- /dev/null +++ b/lib/puppet/application/string.rb @@ -0,0 +1,95 @@ +require 'puppet/application' +require 'puppet/string' + +class Puppet::Application::String < Puppet::Application + + should_parse_config + run_mode :agent + + option("--debug", "-d") do |arg| + Puppet::Util::Log.level = :debug + end + + option("--verbose", "-v") do + Puppet::Util::Log.level = :info + end + + def list(*arguments) + if arguments.empty? + arguments = %w{terminuses actions} + end + strings.each do |name| + str = "#{name}:\n" + if arguments.include?("terminuses") + begin + terms = terminus_classes(name.to_sym) + str << "\tTerminuses: #{terms.join(", ")}\n" + rescue => detail + puts detail.backtrace if Puppet[:trace] + $stderr.puts "Could not load terminuses for #{name}: #{detail}" + end + end + + if arguments.include?("actions") + begin + actions = actions(name.to_sym) + str << "\tActions: #{actions.join(", ")}\n" + rescue => detail + puts detail.backtrace if Puppet[:trace] + $stderr.puts "Could not load actions for #{name}: #{detail}" + end + end + + print str + end + end + + attr_accessor :verb, :name, :arguments + + def main + # Call the method associated with the provided action (e.g., 'find'). + send(verb, *arguments) + end + + def setup + Puppet::Util::Log.newdestination :console + + load_applications # Call this to load all of the apps + + @verb, @arguments = command_line.args + @arguments ||= [] + + validate + end + + def validate + unless verb + raise "You must specify 'find', 'search', 'save', or 'destroy' as a verb; 'save' probably does not work right now" + end + + unless respond_to?(verb) + raise "Command '#{verb}' not found for 'string'" + end + end + + def strings + Puppet::String.strings + end + + def terminus_classes(indirection) + Puppet::Indirector::Terminus.terminus_classes(indirection).collect { |t| t.to_s }.sort + end + + def actions(indirection) + return [] unless string = Puppet::String[indirection, '0.0.1'] + string.load_actions + return string.actions.sort { |a,b| a.to_s <=> b.to_s } + end + + def load_applications + command_line.available_subcommands.each do |app| + command_line.require_application app + end + end +end + |
