diff --git a/lib/puppet/application/faces.rb b/lib/puppet/application/faces.rb index 904a0cccc..a7b227e23 100644 --- a/lib/puppet/application/faces.rb +++ b/lib/puppet/application/faces.rb @@ -1,95 +1,88 @@ require 'puppet/application' require 'puppet/faces' class Puppet::Application::Faces < Puppet::Application should_parse_config run_mode :agent option("--debug", "-d") do |arg| Puppet::Util::Log.level = :debug end + option("--help", "-h") do |arg| + puts "Usage: puppet faces [actions|terminuses] +Lists all available interfaces, and by default includes all available terminuses and actions. +" + end + option("--verbose", "-v") do Puppet::Util::Log.level = :info end def list(*arguments) if arguments.empty? arguments = %w{terminuses actions} end faces.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 + attr_accessor :name, :arguments def main - # Call the method associated with the provided action (e.g., 'find'). - send(verb, *arguments) + list(*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 = 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 'faces'" - end end def faces Puppet::Faces.faces end def terminus_classes(indirection) Puppet::Indirector::Terminus.terminus_classes(indirection).collect { |t| t.to_s }.sort end def actions(indirection) return [] unless faces = Puppet::Faces[indirection, '0.0.1'] faces.load_actions return faces.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 diff --git a/spec/unit/application/faces_spec.rb b/spec/unit/application/faces_spec.rb index 0b84493d2..c4d15a297 100755 --- a/spec/unit/application/faces_spec.rb +++ b/spec/unit/application/faces_spec.rb @@ -1,10 +1,16 @@ #!/usr/bin/env ruby require 'spec_helper' require 'puppet/application/faces' describe Puppet::Application::Faces do it "should be an application" do Puppet::Application::Faces.superclass.should equal(Puppet::Application) end + + it "should always call 'list'" do + faces = Puppet::Application::Faces.new + faces.expects(:list) + faces.main + end end