summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRein Henrichs <reinh@reinh.com>2010-03-30 15:08:52 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commitbe0ecf84edf051df84792067f6d873a70642872f (patch)
treec303cfaaec27278163fc649c29155a76dfc94562
parent7a327775c14fc5fed3998918e9c69af939380617 (diff)
downloadpuppet-be0ecf84edf051df84792067f6d873a70642872f.tar.gz
puppet-be0ecf84edf051df84792067f6d873a70642872f.tar.xz
puppet-be0ecf84edf051df84792067f6d873a70642872f.zip
Initial puppet single executable
- puppet executable delegates to available applications and provides basic usage information - Puppet::Application.applications accessor added for access by main executable - Ugly hack to make RDoc::usage work
-rw-r--r--lib/puppet/application.rb14
-rwxr-xr-xsbin/puppet17
2 files changed, 29 insertions, 2 deletions
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 2882c8191..0b8e3d9d4 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -89,7 +89,11 @@ require 'optparse'
class Puppet::Application
include Puppet::Util
+ SBINDIR = File.expand_path(File.dirname(__FILE__)) + '/../../sbin'
+
@@applications = {}
+ def self.applications; @@applications end
+
class << self
include Puppet::Util
end
@@ -173,7 +177,7 @@ class Puppet::Application
def initialize(name, banner = nil, &block)
@opt_parser = OptionParser.new(banner)
- name = symbolize(name)
+ @name = symbolize(name)
init_default
@@ -181,7 +185,7 @@ class Puppet::Application
instance_eval(&block) if block_given?
- @@applications[name] = self
+ @@applications[@name] = self
end
# initialize default application behaviour
@@ -292,6 +296,12 @@ class Puppet::Application
def help
if Puppet.features.usage?
+ # RH:FIXME: My goodness, this is ugly.
+ ::RDoc.const_set("PuppetSourceFile", @name)
+ def (::RDoc).caller
+ file = `grep -l 'Puppet::Application\\[:#{::RDoc::PuppetSourceFile}\\]' #{SBINDIR}/*`.chomp
+ super << "#{file}:0"
+ end
::RDoc::usage && exit
else
puts "No help available unless you have RDoc::usage installed"
diff --git a/sbin/puppet b/sbin/puppet
new file mode 100755
index 000000000..d3472cc9d
--- /dev/null
+++ b/sbin/puppet
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+appdir = File.join('puppet', 'application')
+builtins = Dir[File.join(appdir, '*.rb')].map{|fn| File.basename(fn, '.rb')}
+
+usage = "Usage: puppet command <space separated arguments>"
+available = "Available commands are: #{builtins.sort.join(', ')}"
+
+command_name = ARGV.empty? || ARGV.first[/^-/] ? nil : ARGV.shift # subcommand?
+if command_name.nil? # main
+ puts usage, available
+elsif builtins.include?(command_name) #subcommand
+ require File.join(appdir, command_name)
+ Puppet::Application[command_name].run
+else
+ abort "Error: Unknown command #{command_name}.\n#{usage}\n#{available}"
+end