diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2010-04-30 14:54:07 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 63e2e56d3172bdc80aaca5f5ddde5811728e3c76 (patch) | |
| tree | 38e3607fe83223d135f1c327682dbd8698bb138d /lib/puppet/application | |
| parent | b6e2ce6a85c953fcd57a3b837ccaa794a634dc22 (diff) | |
| download | puppet-63e2e56d3172bdc80aaca5f5ddde5811728e3c76.tar.gz puppet-63e2e56d3172bdc80aaca5f5ddde5811728e3c76.tar.xz puppet-63e2e56d3172bdc80aaca5f5ddde5811728e3c76.zip | |
feature #2276 Single Executable: subcommand method
Extract the logic to determine the subcommand name into a method.
Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
Diffstat (limited to 'lib/puppet/application')
| -rw-r--r-- | lib/puppet/application/apply.rb | 8 | ||||
| -rw-r--r-- | lib/puppet/application/cert.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/application/describe.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/application/doc.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/application/filebucket.rb | 15 | ||||
| -rw-r--r-- | lib/puppet/application/resource.rb | 7 |
6 files changed, 22 insertions, 16 deletions
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb index 787ce375f..d977cf1d0 100644 --- a/lib/puppet/application/apply.rb +++ b/lib/puppet/application/apply.rb @@ -66,10 +66,10 @@ Puppet::Application.new(:apply) do command(:parseonly) do # Set our code or file to use. - if options[:code] or ARGV.length == 0 + if options[:code] or Puppet::Util::CommandLine.args.length == 0 Puppet[:code] = options[:code] || STDIN.read else - Puppet[:manifest] = ARGV.shift + Puppet[:manifest] = Puppet::Util::CommandLine.args.shift end begin Puppet::Resource::TypeCollection.new(Puppet[:environment]).perform_initial_import @@ -82,10 +82,10 @@ Puppet::Application.new(:apply) do command(:main) do # Set our code or file to use. - if options[:code] or ARGV.length == 0 + if options[:code] or Puppet::Util::CommandLine.args.length == 0 Puppet[:code] = options[:code] || STDIN.read else - Puppet[:manifest] = ARGV.shift + Puppet[:manifest] = Puppet::Util::CommandLine.args.shift end # Collect our facts. diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb index f48e5301a..7a7784b09 100644 --- a/lib/puppet/application/cert.rb +++ b/lib/puppet/application/cert.rb @@ -44,7 +44,7 @@ Puppet::Application.new(:cert) do if @all hosts = :all else - hosts = ARGV.collect { |h| puts h; h.downcase } + hosts = Puppet::Util::CommandLine.args.collect { |h| puts h; h.downcase } end begin @ca.apply(:revoke, :to => hosts) if @mode == :destroy diff --git a/lib/puppet/application/describe.rb b/lib/puppet/application/describe.rb index d3d335496..ea4ac162c 100644 --- a/lib/puppet/application/describe.rb +++ b/lib/puppet/application/describe.rb @@ -202,7 +202,7 @@ Puppet::Application.new(:describe,"#{$0} [options] [type]") do end setup do - options[:types] = ARGV.dup + options[:types] = Puppet::Util::CommandLine.args.dup unless options[:list] || options[:types].size > 0 handle_help(nil) end diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb index 32f9ba75c..0a11d6045 100644 --- a/lib/puppet/application/doc.rb +++ b/lib/puppet/application/doc.rb @@ -70,7 +70,7 @@ Puppet::Application.new(:doc) do files += env.modulepath files << File.dirname(env[:manifest]) end - files += ARGV + files += Puppet::Util::CommandLine.args Puppet.info "scanning: %s" % files.inspect Puppet.settings.setdefaults("puppetdoc", "document_all" => [false, "Document all resources"] @@ -167,7 +167,7 @@ Puppet::Application.new(:doc) do setup do # sole manifest documentation - if ARGV.size > 0 + if Puppet::Util::CommandLine.args.size > 0 options[:mode] = :rdoc @manifest = true end diff --git a/lib/puppet/application/filebucket.rb b/lib/puppet/application/filebucket.rb index ed67009aa..cd7c854af 100644 --- a/lib/puppet/application/filebucket.rb +++ b/lib/puppet/application/filebucket.rb @@ -12,18 +12,23 @@ Puppet::Application.new(:filebucket) do option("--remote","-r") option("--verbose","-v") + class << self + attr :args + end + dispatch do - ARGV.shift + @args = Puppet::Util::CommandLine.args + args.shift end command(:get) do - md5 = ARGV.shift + md5 = args.shift out = @client.getfile(md5) print out end command(:backup) do - ARGV.each do |file| + args.each do |file| unless FileTest.exists?(file) $stderr.puts "%s: no such file" % file next @@ -38,8 +43,8 @@ Puppet::Application.new(:filebucket) do end command(:restore) do - file = ARGV.shift - md5 = ARGV.shift + file = args.shift + md5 = args.shift @client.restore(file, md5) end diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb index ae4349850..78aed95c5 100644 --- a/lib/puppet/application/resource.rb +++ b/lib/puppet/application/resource.rb @@ -38,11 +38,12 @@ Puppet::Application.new(:resource) do end command(:main) do - type = ARGV.shift or raise "You must specify the type to display" + args = Puppet::Util::CommandLine.args + type = args.shift or raise "You must specify the type to display" typeobj = Puppet::Type.type(type) or raise "Could not find type #{type}" - name = ARGV.shift + name = args.shift params = {} - ARGV.each do |setting| + args.each do |setting| if setting =~ /^(\w+)=(.+)$/ params[$1] = $2 else |
