summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-04-30 15:47:15 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit5683fd983b9a165ffbb8f08e67cfe903ec0e41b7 (patch)
treeb1a908be53502201b5ee0f1b37aae8e57a14bf37 /lib
parentd038a1d3ddffdf1366c78fe31118e9f15c1c6ed1 (diff)
downloadpuppet-5683fd983b9a165ffbb8f08e67cfe903ec0e41b7.tar.gz
puppet-5683fd983b9a165ffbb8f08e67cfe903ec0e41b7.tar.xz
puppet-5683fd983b9a165ffbb8f08e67cfe903ec0e41b7.zip
Feature #2276 Single Executable: Pass a commandline object to the application
Refactor so that the command line options only get parsed once Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/application.rb5
-rw-r--r--lib/puppet/application/apply.rb8
-rw-r--r--lib/puppet/application/cert.rb2
-rw-r--r--lib/puppet/application/describe.rb2
-rw-r--r--lib/puppet/application/doc.rb4
-rw-r--r--lib/puppet/application/filebucket.rb2
-rw-r--r--lib/puppet/application/resource.rb2
-rw-r--r--lib/puppet/util/command_line.rb2
8 files changed, 14 insertions, 13 deletions
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 49a146ffe..f72714b12 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -229,7 +229,7 @@ class Puppet::Application
end
end
- attr_reader :options, :opt_parser
+ attr_reader :options, :opt_parser, :command_line
# Every app responds to --version
option("--version", "-V") do |arg|
@@ -250,7 +250,8 @@ class Puppet::Application
def preinit
end
- def initialize
+ def initialize(command_line = nil)
+ @command_line = command_line || Puppet::Util::CommandLine.new
@opt_parser = self.class.new_option_parser( self )
@options = {}
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index 88385f0a0..fde0c9b8d 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -66,10 +66,10 @@ class Puppet::Application::Apply < Puppet::Application
def parseonly
# Set our code or file to use.
- if options[:code] or Puppet::Util::CommandLine.args.length == 0
+ if options[:code] or command_line.args.length == 0
Puppet[:code] = options[:code] || STDIN.read
else
- Puppet[:manifest] = Puppet::Util::CommandLine.args.shift
+ Puppet[:manifest] = command_line.args.shift
end
begin
Puppet::Resource::TypeCollection.new(Puppet[:environment]).perform_initial_import
@@ -82,10 +82,10 @@ class Puppet::Application::Apply < Puppet::Application
def main
# Set our code or file to use.
- if options[:code] or Puppet::Util::CommandLine.args.length == 0
+ if options[:code] or command_line.args.length == 0
Puppet[:code] = options[:code] || STDIN.read
else
- Puppet[:manifest] = Puppet::Util::CommandLine.args.shift
+ Puppet[:manifest] = command_line.args.shift
end
# Collect our facts.
diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb
index 92da03ca7..a4ee5fef3 100644
--- a/lib/puppet/application/cert.rb
+++ b/lib/puppet/application/cert.rb
@@ -44,7 +44,7 @@ class Puppet::Application::Cert < Puppet::Application
if @all
hosts = :all
else
- hosts = Puppet::Util::CommandLine.args.collect { |h| puts h; h.downcase }
+ hosts = command_line.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 45f017a48..ae33fb92a 100644
--- a/lib/puppet/application/describe.rb
+++ b/lib/puppet/application/describe.rb
@@ -203,7 +203,7 @@ class Puppet::Application::Describe < Puppet::Application
end
def setup
- options[:types] = Puppet::Util::CommandLine.args.dup
+ options[:types] = command_line.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 295cd6771..74cde98bd 100644
--- a/lib/puppet/application/doc.rb
+++ b/lib/puppet/application/doc.rb
@@ -70,7 +70,7 @@ class Puppet::Application::Doc < Puppet::Application
files += env.modulepath
files << File.dirname(env[:manifest])
end
- files += Puppet::Util::CommandLine.args
+ files += command_line.args
Puppet.info "scanning: %s" % files.inspect
Puppet.settings.setdefaults("puppetdoc",
"document_all" => [false, "Document all resources"]
@@ -167,7 +167,7 @@ class Puppet::Application::Doc < Puppet::Application
def setup
# sole manifest documentation
- if Puppet::Util::CommandLine.args.size > 0
+ if command_line.args.size > 0
options[:mode] = :rdoc
@manifest = true
end
diff --git a/lib/puppet/application/filebucket.rb b/lib/puppet/application/filebucket.rb
index ddc46e394..8e930f5e4 100644
--- a/lib/puppet/application/filebucket.rb
+++ b/lib/puppet/application/filebucket.rb
@@ -15,7 +15,7 @@ class Puppet::Application::Filebucket < Puppet::Application
attr :args
def run_command
- @args = Puppet::Util::CommandLine.args
+ @args = command_line.args
command = args.shift
return send(command) if %w[get backup restore].include? command
help
diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb
index 52320e7a1..6a8c4e47c 100644
--- a/lib/puppet/application/resource.rb
+++ b/lib/puppet/application/resource.rb
@@ -38,7 +38,7 @@ class Puppet::Application::Resource < Puppet::Application
end
def main
- args = Puppet::Util::CommandLine.args
+ args = command_line.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 = args.shift
diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb
index 6e67fd706..e6656985f 100644
--- a/lib/puppet/util/command_line.rb
+++ b/lib/puppet/util/command_line.rb
@@ -75,7 +75,7 @@ module Puppet
puts self.class.usage_message
elsif self.class.available_subcommands.include?(subcommand_name) #subcommand
require File.join(self.class.appdir, subcommand_name)
- Puppet::Application[subcommand_name].run
+ Puppet::Application.find(subcommand_name).new(self).run
else
abort "Error: Unknown command #{subcommand_name}.\n#{usage_message}"
end