diff --git a/bin/puppet b/bin/puppet index bf4ee3a95..5e619de6e 100755 --- a/bin/puppet +++ b/bin/puppet @@ -1,20 +1,89 @@ #!/usr/bin/env ruby +# +# = Synopsis +# +# Run a stand-alone +puppet+ manifest. +# +# = Usage +# +# puppet apply [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose] [-e|--execute] +# [--detailed-exitcodes] [-l|--logdest ] +# +# = Description +# +# This is the standalone puppet execution tool; use it to execute +# individual manifests that you write. If you need to execute site-wide +# manifests, use 'puppet agent' and 'puppet master'. +# +# = Options +# +# Note that any configuration parameter that's valid in the configuration file +# is also a valid long argument. For example, 'ssldir' is a valid configuration +# parameter, so you can specify '--ssldir ' as an argument. +# +# See the configuration file documentation at +# http://reductivelabs.com/trac/puppet/wiki/ConfigurationReference for +# the full list of acceptable parameters. A commented list of all +# configuration options can also be generated by running puppet with +# '--genconfig'. +# +# debug:: +# Enable full debugging. +# +# detailed-exitcodes:: +# Provide transaction information via exit codes. If this is enabled, an exit +# code of '2' means there were changes, and an exit code of '4' means that there +# were failures during the transaction. +# +# help:: +# Print this help message +# +# loadclasses:: +# Load any stored classes. 'puppet agent' caches configured classes (usually at +# /etc/puppet/classes.txt), and setting this option causes all of those classes +# to be set in your puppet manifest. +# +# logdest:: +# Where to send messages. Choose between syslog, the console, and a log file. +# Defaults to sending messages to the console. +# +# execute:: +# Execute a specific piece of Puppet code +# +# verbose:: +# Print extra information. +# +# = Example +# +# puppet -l /tmp/manifest.log manifest.pp +# +# = Author +# +# Luke Kanies +# +# = Copyright +# +# Copyright (c) 2005 Reductive Labs, LLC +# Licensed under the GNU Public License + +#Puppet::Application[:apply].run # this is so the RDoc::usage hack can find this file + appdir = File.join('puppet', 'application') absolute_appdir = $:.collect { |x| File.join(x,'puppet','application') }.detect{ |x| File.directory?(x) } builtins = Dir[File.join(absolute_appdir, '*.rb')].map{|fn| File.basename(fn, '.rb')} usage = "Usage: puppet command " available = "Available commands are: #{builtins.sort.join(', ')}" require 'puppet/util/command_line' $puppet_subcommand_name = Puppet::Util::CommandLine.shift_subcommand_from_argv if $puppet_subcommand_name.nil? puts usage, available elsif builtins.include?($puppet_subcommand_name) #subcommand require File.join(appdir, $puppet_subcommand_name) Puppet::Application[$puppet_subcommand_name].run else abort "Error: Unknown command #{$puppet_subcommand_name}.\n#{usage}\n#{available}" end diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb index ba474df91..f231ee7f8 100644 --- a/lib/puppet/util/command_line.rb +++ b/lib/puppet/util/command_line.rb @@ -1,13 +1,14 @@ module Puppet module Util module CommandLine def self.shift_subcommand_from_argv( argv = ARGV, stdin = STDIN ) case argv.first when nil; "apply" unless stdin.tty? # ttys get usage info + when "--help"; nil # help should give you usage, not the help for `puppet apply` when /^-|\.pp$|\.rb$/; "apply" else argv.shift end end end end end diff --git a/spec/unit/util/command_line.rb b/spec/unit/util/command_line.rb index b8fd87643..265535b78 100644 --- a/spec/unit/util/command_line.rb +++ b/spec/unit/util/command_line.rb @@ -1,70 +1,78 @@ #!/usr/bin/env ruby Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } require 'puppet/util/command_line' describe Puppet::Util::CommandLine do before do @tty = stub("tty", :tty? => true ) @pipe = stub("pipe", :tty? => false) end it "should pull off the first argument if it looks like a subcommand" do args = %w( client --help whatever.pp ) command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) command.should == "client" args.should == %w( --help whatever.pp ) end it "should use 'apply' if the first argument looks like a .pp file" do args = %w( whatever.pp ) command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) command.should == "apply" args.should == %w( whatever.pp ) end it "should use 'apply' if the first argument looks like a .rb file" do args = %w( whatever.rb ) command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) command.should == "apply" args.should == %w( whatever.rb ) end it "should use 'apply' if the first argument looks like a flag" do args = %w( --debug ) command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) command.should == "apply" args.should == %w( --debug ) end it "should use 'apply' if the first argument is -" do args = %w( - ) command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) command.should == "apply" args.should == %w( - ) end + it "should return nil if the first argument is --help" do + args = %w( --help ) + command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) + + command.should == nil + end + + it "should return nil if there are no arguments on a tty" do args = [] command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty ) command.should == nil args.should == [] end it "should use 'apply' if there are no arguments on a pipe" do args = [] command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @pipe ) command.should == "apply" args.should == [] end end