summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2009-02-14 14:40:25 +0100
committerBrice Figureau <brice-puppet@daysofwonder.com>2009-02-16 20:12:11 +0100
commit0f43fd6c894dd2be7f08209f28caf34be768f238 (patch)
tree33f55bdd8441992dd46189e08634d21857b72d66
parent156fb81ca914f6d697dc2cb81788a1d9ab5a23e4 (diff)
downloadpuppet-0f43fd6c894dd2be7f08209f28caf34be768f238.tar.gz
puppet-0f43fd6c894dd2be7f08209f28caf34be768f238.tar.xz
puppet-0f43fd6c894dd2be7f08209f28caf34be768f238.zip
Move --version handling to Puppet::Application
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
-rw-r--r--lib/puppet/application.rb22
-rw-r--r--lib/puppet/application/filebucket.rb5
-rw-r--r--lib/puppet/application/puppet.rb5
-rw-r--r--lib/puppet/application/puppetca.rb3
-rw-r--r--lib/puppet/application/puppetd.rb5
-rw-r--r--lib/puppet/application/puppetmasterd.rb5
-rw-r--r--lib/puppet/application/puppetrun.rb5
-rwxr-xr-xspec/unit/application.rb12
-rw-r--r--spec/unit/application/filebucket.rb12
-rw-r--r--spec/unit/application/puppet.rb9
-rwxr-xr-xspec/unit/application/puppetd.rb8
-rw-r--r--spec/unit/application/puppetmasterd.rb6
-rwxr-xr-xspec/unit/application/puppetrun.rb6
13 files changed, 29 insertions, 74 deletions
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 3cd7598bb..3f3b2e10e 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -175,6 +175,17 @@ class Puppet::Application
name = symbolize(name)
+ init_default
+
+ @options = {}
+
+ instance_eval(&block) if block_given?
+
+ @@applications[name] = self
+ end
+
+ # initialize default application behaviour
+ def init_default
setup do
default_setup
end
@@ -187,15 +198,14 @@ class Puppet::Application
preinit do
end
+ option("--version", "-V") do |arg|
+ puts "%s" % Puppet.version
+ exit
+ end
+
option("--help", "-h") do |v|
help
end
-
- @options = {}
-
- instance_eval(&block) if block_given?
-
- @@applications[name] = self
end
# This is the main application entry point
diff --git a/lib/puppet/application/filebucket.rb b/lib/puppet/application/filebucket.rb
index f456e0dcc..0723054df 100644
--- a/lib/puppet/application/filebucket.rb
+++ b/lib/puppet/application/filebucket.rb
@@ -6,11 +6,6 @@ Puppet::Application.new(:filebucket) do
should_not_parse_config
- option("--version", "-V") do |arg|
- puts "%s" % Puppet.version
- exit
- end
-
option("--bucket BUCKET","-b")
option("--debug","-d")
option("--local","-l")
diff --git a/lib/puppet/application/puppet.rb b/lib/puppet/application/puppet.rb
index c8ca81975..5b4386e8c 100644
--- a/lib/puppet/application/puppet.rb
+++ b/lib/puppet/application/puppet.rb
@@ -23,11 +23,6 @@ Puppet::Application.new(:puppet) do
end
end
- option("--version", "-V") do |arg|
- puts "%s" % Puppet.version
- exit
- end
-
dispatch do
return Puppet[:parseonly] ? :parseonly : :main
end
diff --git a/lib/puppet/application/puppetca.rb b/lib/puppet/application/puppetca.rb
index 17ff38a2b..09de6c302 100644
--- a/lib/puppet/application/puppetca.rb
+++ b/lib/puppet/application/puppetca.rb
@@ -32,13 +32,10 @@ Puppet::Application.new(:puppetca) do
end
end
- option("--version","-V")
-
option("--verbose", "-v") do
Puppet::Util::Log.level = :info
end
-
command(:main) do
if @all
hosts = :all
diff --git a/lib/puppet/application/puppetd.rb b/lib/puppet/application/puppetd.rb
index 4c050c7a8..3efb0ef0a 100644
--- a/lib/puppet/application/puppetd.rb
+++ b/lib/puppet/application/puppetd.rb
@@ -56,11 +56,6 @@ Puppet::Application.new(:puppetd) do
end
end
- option("--version", "-V") do |arg|
- puts "%s" % Puppet.version
- exit
- end
-
option("--no-client") do |arg|
options[:client] = false
end
diff --git a/lib/puppet/application/puppetmasterd.rb b/lib/puppet/application/puppetmasterd.rb
index b563c0992..15426ad96 100644
--- a/lib/puppet/application/puppetmasterd.rb
+++ b/lib/puppet/application/puppetmasterd.rb
@@ -22,11 +22,6 @@ Puppet::Application.new(:puppetmasterd) do
end
end
- option("--version", "-V") do |arg|
- puts "%s" % Puppet.version
- exit
- end
-
preinit do
trap(:INT) do
$stderr.puts "Cancelling startup"
diff --git a/lib/puppet/application/puppetrun.rb b/lib/puppet/application/puppetrun.rb
index 9e9d2b81f..42f02c796 100644
--- a/lib/puppet/application/puppetrun.rb
+++ b/lib/puppet/application/puppetrun.rb
@@ -25,11 +25,6 @@ Puppet::Application.new(:puppetrun) do
option("--ping","-P")
option("--test")
- option("--version", "-V") do |arg|
- puts "%s" % Puppet.version
- exit
- end
-
option("--host HOST") do |arg|
@hosts << arg
end
diff --git a/spec/unit/application.rb b/spec/unit/application.rb
index a10f4fbe7..a5da191e3 100755
--- a/spec/unit/application.rb
+++ b/spec/unit/application.rb
@@ -83,6 +83,18 @@ describe Puppet::Application do
end
+ describe "when using --version" do
+ it "should declare a version option" do
+ @app.should respond_to(:handle_version)
+ end
+
+ it "should exit after printing the version" do
+ @app.stubs(:puts)
+
+ lambda { @app.handle_version(nil) }.should raise_error(SystemExit)
+ end
+ end
+
describe "when dealing with an argument not declared directly by the application" do
it "should pass it to handle_unknown if this method exists" do
Puppet.settings.stubs(:optparse_addargs).returns([["--not-handled"]])
diff --git a/spec/unit/application/filebucket.rb b/spec/unit/application/filebucket.rb
index 0050183f5..2ddf78d90 100644
--- a/spec/unit/application/filebucket.rb
+++ b/spec/unit/application/filebucket.rb
@@ -25,11 +25,7 @@ describe "Filebucket" do
@filebucket.should respond_to(:restore)
end
- it "should declare a version option" do
- @filebucket.should respond_to(:handle_version)
- end
-
- [:bucket, :debug, :help, :local, :remote, :verbose].each do |option|
+ [:bucket, :debug, :local, :remote, :verbose].each do |option|
it "should declare handle_#{option} method" do
@filebucket.should respond_to("handle_#{option}".to_sym)
end
@@ -40,12 +36,6 @@ describe "Filebucket" do
end
end
- it "should exit after printing the version" do
- @filebucket.stubs(:puts)
-
- lambda { @filebucket.handle_version(nil) }.should raise_error(SystemExit)
- end
-
describe "during setup" do
before :each do
diff --git a/spec/unit/application/puppet.rb b/spec/unit/application/puppet.rb
index 3bad64309..e7a6bb44a 100644
--- a/spec/unit/application/puppet.rb
+++ b/spec/unit/application/puppet.rb
@@ -9,10 +9,6 @@ describe "Puppet" do
@puppet = Puppet::Application[:puppet]
end
- it "should declare a version option" do
- @puppet.should respond_to(:handle_version)
- end
-
[:debug,:execute,:loadclasses,:verbose,:use_nodes,:detailed_exitcodes].each do |option|
it "should declare handle_#{option} method" do
@puppet.should respond_to("handle_#{option}".to_sym)
@@ -29,11 +25,6 @@ describe "Puppet" do
end
describe "when applying options" do
- it "should exit after printing the version" do
- @puppet.stubs(:puts)
-
- lambda { @puppet.handle_version(nil) }.should raise_error(SystemExit)
- end
it "should set the log destination with --logdest" do
Puppet::Log.expects(:newdestination).with("console")
diff --git a/spec/unit/application/puppetd.rb b/spec/unit/application/puppetd.rb
index 7bfd822ea..3abfaf023 100755
--- a/spec/unit/application/puppetd.rb
+++ b/spec/unit/application/puppetd.rb
@@ -32,10 +32,6 @@ describe "puppetd" do
@puppetd.should respond_to(:run_preinit)
end
- it "should declare a version option" do
- @puppetd.should respond_to(:handle_version)
- end
-
describe "in preinit" do
before :each do
@pupetd.stubs(:trap)
@@ -93,10 +89,6 @@ describe "puppetd" do
@puppetd.options[:serve].should == [ :handler ]
end
- it "should exit after printing the version" do
- lambda { @puppetd.handle_version(nil) }.should raise_error(SystemExit)
- end
-
it "should set client to false with --no-client" do
@puppetd.handle_no_client(nil)
@puppetd.options[:client].should be_false
diff --git a/spec/unit/application/puppetmasterd.rb b/spec/unit/application/puppetmasterd.rb
index 773563ac6..606617d9e 100644
--- a/spec/unit/application/puppetmasterd.rb
+++ b/spec/unit/application/puppetmasterd.rb
@@ -66,12 +66,6 @@ describe "PuppetMaster" do
end
describe "when applying options" do
- it "should exit after printing the version" do
- @puppetmasterd.stubs(:puts)
-
- lambda { @puppetmasterd.handle_version(nil) }.should raise_error(SystemExit)
- end
-
it "should set the log destination with --logdest" do
Puppet::Log.expects(:newdestination).with("console")
diff --git a/spec/unit/application/puppetrun.rb b/spec/unit/application/puppetrun.rb
index 5d033e960..89725027c 100755
--- a/spec/unit/application/puppetrun.rb
+++ b/spec/unit/application/puppetrun.rb
@@ -70,12 +70,6 @@ describe "puppetrun" do
end
end
- it "should exit after printing the version" do
- @puppetrun.stubs(:puts)
-
- lambda { @puppetrun.handle_version(nil) }.should raise_error(SystemExit)
- end
-
it "should add to the host list with the host option" do
@puppetrun.handle_host('host')