[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:33:20 UTC 2010


The following commit has been merged in the upstream branch:
commit d038a1d3ddffdf1366c78fe31118e9f15c1c6ed1
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Fri Apr 30 16:05:43 2010 -0700

    Refactor #3706 Reify eigenclasses of Applications
    
    The Puppet::Application DSL is complicated by the fact that it operates
    on eigenclasses of instances of Puppet::Application, rather than
    subclassing it.
    This patch reifies the eigenclasses as subclasses of
    Puppet::Application.
    
    Signed-off-by: Jesse Wolfe <jes5199 at gmail.com>

diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 7b404a9..49a146f 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -8,26 +8,28 @@ require 'optparse'
 # * representing execution status
 #
 # === Usage
-# The application is a Puppet::Application object that register itself in the list
-# of available application. Each application needs a +name+ and a getopt +options+
-# description array.
+# An application is a subclass of Puppet::Application.
 #
-# The executable uses the application object like this:
+# For legacy compatibility,
 #      Puppet::Application[:example].run
+# is equivalent to  
+#      Puppet::Application::Example.new.run
 #
 #
-# Puppet::Application.new(:example) do
+# class Puppet::Application::Example << Puppet::Application
 #
-#     preinit do
+#     def preinit
 #         # perform some pre initialization
 #         @all = false
 #     end
 #
-#     # dispatch is called to know to what command to call
-#     dispatch do
-#         Puppet::Util::CommandLine.args.shift
+#     # run_command is called to actually run the specified command
+#     def run_command
+#         send Puppet::Util::CommandLine.args.shift
 #     end
 #
+#     # option uses metaprogramming to create a method
+#     # and also tells the option parser how to invoke that method
 #     option("--arg ARGUMENT") do |v|
 #         @args << v
 #     end
@@ -40,18 +42,18 @@ require 'optparse'
 #         @all = v
 #     end
 #
-#     unknown do |opt,arg|
+#     def handle_unknown(opt,arg)
 #         # last chance to manage an option
 #         ...
 #         # let's say to the framework we finally handle this option
 #         true
 #     end
 #
-#     command(:read) do
+#     def read
 #         # read action
 #     end
 #
-#     command(:write) do
+#     def write
 #         # writeaction
 #     end
 #
@@ -117,9 +119,6 @@ class Puppet::Application
 
     BINDIRS = %w{sbin bin}.map{|dir| File.expand_path(File.dirname(__FILE__)) + "/../../#{dir}/*"}.join(" ")
 
-    @@applications = {}
-    def self.applications; @@applications end
-
     class << self
         include Puppet::Util
 
@@ -172,128 +171,97 @@ class Puppet::Application
             Process.kill(:HUP, $$) if restart_requested?
             result
         end
-    end
 
-    attr_reader :options, :opt_parser
+        def should_parse_config
+            @parse_config = true
+        end
 
-    def self.[](name)
-        name = symbolize(name)
-        @@applications[name]
-    end
+        def should_not_parse_config
+            @parse_config = false
+        end
 
-    def should_parse_config
-        @parse_config = true
-    end
+        def should_parse_config?
+            if ! defined? @parse_config
+                @parse_config = true
+            end
+            return @parse_config
+        end
 
-    def should_not_parse_config
-        @parse_config = false
-    end
+        # used to declare code that handle an option
+        def option(*options, &block)
+            long = options.find { |opt| opt =~ /^--/ }.gsub(/^--(?:\[no-\])?([^ =]+).*$/, '\1' ).gsub('-','_')
+            fname = symbolize("handle_#{long}")
+            if (block_given?)
+                define_method(fname, &block)
+            else
+                define_method(fname) do |value|
+                    self.options["#{long}".to_sym] = value
+                end
+            end
+            @opt_parser_commands ||= []
+            @opt_parser_commands << [options, fname]
+        end
 
-    def should_parse_config?
-        unless @parse_config.nil?
-            return @parse_config
+        def banner(banner = nil)
+            @banner = banner unless banner.nil?
         end
-        @parse_config = true
-    end
 
-    # used to declare a new command
-    def command(name, &block)
-        meta_def(symbolize(name), &block)
-    end
+        def new_option_parser( target )
+            @banner ||= nil
 
-    # used as a catch-all for unknown option
-    def unknown(&block)
-        meta_def(:handle_unknown, &block)
-    end
+            opt_parser = OptionParser.new(@banner)
 
-    # used to declare code that handle an option
-    def option(*options, &block)
-        long = options.find { |opt| opt =~ /^--/ }.gsub(/^--(?:\[no-\])?([^ =]+).*$/, '\1' ).gsub('-','_')
-        fname = "handle_#{long}"
-        if (block_given?)
-            meta_def(symbolize(fname), &block)
-        else
-            meta_def(symbolize(fname)) do |value|
-                self.options["#{long}".to_sym] = value
+            @opt_parser_commands ||= []
+            @opt_parser_commands.each do |options, fname|
+                opt_parser.on(*options) do |value|
+                    target.send(fname, value)
+                end
             end
+            opt_parser
         end
-        @opt_parser.on(*options) do |value|
-            self.send(symbolize(fname), value)
+
+        def find(name)
+            self.const_get(name.to_s.capitalize)
         end
-    end
 
-    # used to declare accessor in a more natural way in the
-    # various applications
-    def attr_accessor(*args)
-        args.each do |arg|
-            meta_def(arg) do
-                instance_variable_get("@#{arg}".to_sym)
-            end
-            meta_def("#{arg}=") do |value|
-                instance_variable_set("@#{arg}".to_sym, value)
-            end
+        def [](name)
+            find(name).new
         end
     end
 
-    # used to declare code run instead the default setup
-    def setup(&block)
-        meta_def(:run_setup, &block)
-    end
+    attr_reader :options, :opt_parser
 
-    # used to declare code to choose which command to run
-    def dispatch(&block)
-        meta_def(:get_command, &block)
+    # Every app responds to --version
+    option("--version", "-V") do |arg|
+        puts "%s" % Puppet.version
+        exit
     end
 
-    # used to execute code before running anything else
-    def preinit(&block)
-        meta_def(:run_preinit, &block)
+    # Every app responds to --help
+    option("--help", "-h") do |v|
+        help
     end
 
-    def initialize(name, banner = nil, &block)
-        @opt_parser = OptionParser.new(banner)
-
-        @name = symbolize(name)
-
-        init_default
-
-        @options = {}
-
-        instance_eval(&block) if block_given?
-
-        @@applications[@name] = self
+    def should_parse_config?
+        self.class.should_parse_config?
     end
 
-    # initialize default application behaviour
-    def init_default
-        setup do
-            default_setup
-        end
-
-        dispatch do
-            :main
-        end
-
-        # empty by default
-        preinit do
-        end
+    # override to execute code before running anything else
+    def preinit
+    end
 
-        option("--version", "-V") do |arg|
-            puts "%s" % Puppet.version
-            exit
-        end
+    def initialize
+        @opt_parser = self.class.new_option_parser( self )
 
-        option("--help", "-h") do |v|
-            help
-        end
+        @options = {}
     end
 
     # This is the main application entry point
     def run
-        exit_on_fail("initialize") { run_preinit }
+        exit_on_fail("initialize") { preinit }
         exit_on_fail("parse options") { parse_options }
         exit_on_fail("parse configuration file") { Puppet.settings.parse } if should_parse_config?
-        exit_on_fail("prepare for execution") { run_setup }
+        exit_on_fail("prepare for execution") { setup }
         exit_on_fail("run") { run_command }
     end
 
@@ -302,14 +270,10 @@ class Puppet::Application
     end
 
     def run_command
-        if command = get_command() and respond_to?(command)
-            send(command)
-        else
-            main
-        end
+        main
     end
 
-    def default_setup
+    def setup
         # Handle the logging settings
         if options[:debug] or options[:verbose]
             Puppet::Util::Log.newdestination(:console)
@@ -370,10 +334,14 @@ class Puppet::Application
         exit(code)
     end
 
+    def name
+        self.class.to_s.sub(/.*::/,"").downcase.to_sym
+    end
+
     def help
         if Puppet.features.usage?
             # RH:FIXME: My goodness, this is ugly.
-            ::RDoc.const_set("PuppetSourceFile", @name)
+            ::RDoc.const_set("PuppetSourceFile", name)
             def (::RDoc).caller
                 docfile = `grep -l 'Puppet::Application\\[:#{::RDoc::PuppetSourceFile}\\]' #{BINDIRS}`.chomp
                 super << "#{docfile}:0"
@@ -384,7 +352,7 @@ class Puppet::Application
             exit
         end
     rescue Errno::ENOENT
-        puts "No help available for puppet #@name"
+        puts "No help available for puppet #{name}"
         exit
     end
 
diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb
index 985d87d..093e5b9 100644
--- a/lib/puppet/application/agent.rb
+++ b/lib/puppet/application/agent.rb
@@ -5,13 +5,13 @@ require 'puppet/daemon'
 require 'puppet/configurer'
 require 'puppet/network/client'
 
-Puppet::Application.new(:agent) do
+class Puppet::Application::Agent < Puppet::Application
 
     should_parse_config
 
     attr_accessor :explicit_waitforcert, :args, :agent, :daemon, :host
 
-    preinit do
+    def preinit
         # Do an initial trap, so that cancels don't get a stack trace.
         trap(:INT) do
             $stderr.puts "Cancelling startup"
@@ -96,13 +96,13 @@ Puppet::Application.new(:agent) do
         @args[:Port] = arg
     end
 
-    dispatch do
-        return :fingerprint if options[:fingerprint]
-        return :onetime if options[:onetime]
-        return :main
+    def run_command
+        return fingerprint if options[:fingerprint]
+        return onetime if options[:onetime]
+        return main
     end
 
-    command(:fingerprint) do
+    def fingerprint
         unless cert = host.certificate || host.certificate_request
            $stderr.puts "Fingerprint asked but no certificate nor certificate request have yet been issued"
            exit(1)
@@ -114,7 +114,7 @@ Puppet::Application.new(:agent) do
         Puppet.notice fingerprint
     end
 
-    command(:onetime) do
+    def onetime
         unless options[:client]
             $stderr.puts "onetime is specified but there is no client"
             exit(43)
@@ -141,7 +141,7 @@ Puppet::Application.new(:agent) do
         end
     end
 
-    command(:main) do
+    def main
         Puppet.notice "Starting Puppet client version %s" % [Puppet.version]
 
         @daemon.start
@@ -207,7 +207,7 @@ Puppet::Application.new(:agent) do
         @daemon.server = server
     end
 
-    setup do
+    def setup
         setup_test if options[:test]
 
         setup_logs
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index d977cf1..88385f0 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -4,7 +4,7 @@ require 'puppet/configurer'
 require 'puppet/network/handler'
 require 'puppet/network/client'
 
-Puppet::Application.new(:apply) do
+class Puppet::Application::Apply < Puppet::Application
 
     should_parse_config
 
@@ -30,17 +30,17 @@ Puppet::Application.new(:apply) do
         end
     end
 
-    dispatch do
+    def run_command
         if options[:catalog]
-            :apply
+            apply
         elsif Puppet[:parseonly]
-            :parseonly
+            parseonly
         else
-            :main
+            main
         end
     end
 
-    command(:apply) do
+    def apply
         require 'puppet/configurer'
 
         if options[:catalog] == "-"
@@ -64,7 +64,7 @@ Puppet::Application.new(:apply) do
         configurer.run :catalog => catalog
     end
 
-    command(:parseonly) do
+    def parseonly
         # Set our code or file to use.
         if options[:code] or Puppet::Util::CommandLine.args.length == 0
             Puppet[:code] = options[:code] || STDIN.read
@@ -80,7 +80,7 @@ Puppet::Application.new(:apply) do
         exit 0
     end
 
-    command(:main) do
+    def main
         # Set our code or file to use.
         if options[:code] or Puppet::Util::CommandLine.args.length == 0
             Puppet[:code] = options[:code] || STDIN.read
@@ -153,7 +153,7 @@ Puppet::Application.new(:apply) do
         end
     end
 
-    setup do
+    def setup
         if Puppet.settings.print_configs?
             exit(Puppet.settings.print_configs ? 0 : 1)
         end
diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb
index 7a7784b..92da03c 100644
--- a/lib/puppet/application/cert.rb
+++ b/lib/puppet/application/cert.rb
@@ -2,7 +2,7 @@ require 'puppet'
 require 'puppet/application'
 require 'puppet/ssl/certificate_authority'
 
-Puppet::Application.new(:cert) do
+class Puppet::Application::Cert < Puppet::Application
 
     should_parse_config
 
@@ -40,7 +40,7 @@ Puppet::Application.new(:cert) do
         Puppet::Util::Log.level = :info
     end
 
-    command(:main) do
+    def main
         if @all
             hosts = :all
         else
@@ -56,7 +56,7 @@ Puppet::Application.new(:cert) do
         end
     end
 
-    setup do
+    def setup
         if Puppet.settings.print_configs?
             exit(Puppet.settings.print_configs ? 0 : 1)
         end
diff --git a/lib/puppet/application/describe.rb b/lib/puppet/application/describe.rb
index ea4ac16..45f017a 100644
--- a/lib/puppet/application/describe.rb
+++ b/lib/puppet/application/describe.rb
@@ -175,7 +175,8 @@ class TypeDoc
 
 end
 
-Puppet::Application.new(:describe,"#{$0} [options] [type]") do
+class Puppet::Application::Describe < Puppet::Application
+    banner "puppet describe [options] [type]"
 
     should_not_parse_config
 
@@ -187,11 +188,11 @@ Puppet::Application.new(:describe,"#{$0} [options] [type]") do
     option("--list", "-l")
     option("--meta","-m")
 
-    preinit do
+    def preinit
         options[:parameters] = true
     end
 
-    command(:main) do
+    def main
         doc = TypeDoc.new
 
         if options[:list]
@@ -201,7 +202,7 @@ Puppet::Application.new(:describe,"#{$0} [options] [type]") do
         end
     end
 
-    setup do
+    def setup
         options[:types] = Puppet::Util::CommandLine.args.dup
         unless options[:list] || options[:types].size > 0
             handle_help(nil)
diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb
index 0a11d60..295cd67 100644
--- a/lib/puppet/application/doc.rb
+++ b/lib/puppet/application/doc.rb
@@ -7,13 +7,13 @@ require 'puppet/util/rdoc'
 $tab = "    "
 Reference = Puppet::Util::Reference
 
-Puppet::Application.new(:doc) do
+class Puppet::Application::Doc < Puppet::Application
 
     should_not_parse_config
 
     attr_accessor :unknown_args, :manifest
 
-    preinit do
+    def preinit
         {:references => [], :mode => :text, :format => :to_rest }.each do |name,value|
             options[name] = value
         end
@@ -52,17 +52,17 @@ Puppet::Application.new(:doc) do
         options[:references] << arg.intern
     end
 
-    unknown do |opt, arg|
+    def handle_unknown( opt, arg )
         @unknown_args << {:opt => opt, :arg => arg }
         true
     end
 
-    dispatch do
-        return options[:mode] if [:rdoc, :trac, :markdown].include?(options[:mode])
-        return :other
+    def run_command
+        return send(options[:mode]) if [:rdoc, :trac, :markdown].include?(options[:mode])
+        return other
     end
 
-    command(:rdoc) do
+    def rdoc
         exit_code = 0
         files = []
         unless @manifest
@@ -93,7 +93,7 @@ Puppet::Application.new(:doc) do
         exit exit_code
     end
 
-    command(:trac) do
+    def trac
         options[:references].each do |name|
             section = Puppet::Util::Reference.reference(name) or raise "Could not find section %s" % name
             unless options[:mode] == :pdf
@@ -102,7 +102,7 @@ Puppet::Application.new(:doc) do
         end
     end
 
-    command(:markdown) do
+    def markdown
         text = ""
         with_contents = false
         exit_code = 0
@@ -127,7 +127,7 @@ Puppet::Application.new(:doc) do
         exit exit_code
     end
 
-    command(:other) do
+    def other
         text = ""
         if options[:references].length > 1
             with_contents = false
@@ -165,7 +165,7 @@ Puppet::Application.new(:doc) do
         exit exit_code
     end
 
-    setup do
+    def setup
         # sole manifest documentation
         if Puppet::Util::CommandLine.args.size > 0
             options[:mode] = :rdoc
diff --git a/lib/puppet/application/filebucket.rb b/lib/puppet/application/filebucket.rb
index cd7c854..ddc46e3 100644
--- a/lib/puppet/application/filebucket.rb
+++ b/lib/puppet/application/filebucket.rb
@@ -2,7 +2,7 @@ require 'puppet'
 require 'puppet/application'
 require 'puppet/file_bucket/dipper'
 
-Puppet::Application.new(:filebucket) do
+class Puppet::Application::Filebucket < Puppet::Application
 
     should_not_parse_config
 
@@ -12,22 +12,22 @@ Puppet::Application.new(:filebucket) do
     option("--remote","-r")
     option("--verbose","-v")
 
-    class << self
-        attr :args
-    end
+    attr :args
 
-    dispatch do
+    def run_command
         @args = Puppet::Util::CommandLine.args
-        args.shift
+        command = args.shift
+        return send(command) if %w[get backup restore].include? command
+        help
     end
 
-    command(:get) do
+    def get
         md5 = args.shift
         out = @client.getfile(md5)
         print out
     end
 
-    command(:backup) do
+    def backup
         args.each do |file|
             unless FileTest.exists?(file)
                 $stderr.puts "%s: no such file" % file
@@ -42,13 +42,13 @@ Puppet::Application.new(:filebucket) do
         end
     end
 
-    command(:restore) do
+    def restore
         file = args.shift
         md5 = args.shift
         @client.restore(file, md5)
     end
 
-    setup do
+    def setup
         Puppet::Log.newdestination(:console)
 
         @client = nil
diff --git a/lib/puppet/application/kick.rb b/lib/puppet/application/kick.rb
index 7b4993b..37d3e53 100644
--- a/lib/puppet/application/kick.rb
+++ b/lib/puppet/application/kick.rb
@@ -4,7 +4,7 @@ require 'puppet/application'
 Puppet.warning "RubyGems not installed" unless Puppet.features.rubygems?
 Puppet.warning "Failed to load ruby LDAP library. LDAP functionality will not be available" unless Puppet.features.ldap?
 
-Puppet::Application.new(:kick) do
+class Puppet::Application::Kick < Puppet::Application
 
     should_not_parse_config
 
@@ -41,17 +41,16 @@ Puppet::Application.new(:kick) do
         end
     end
 
-
-    dispatch do
-        options[:test] ? :test : :main
+    def run_command
+        options[:test] ? test : main
     end
 
-    command(:test) do
+    def test
         puts "Skipping execution in test mode"
         exit(0)
     end
 
-    command(:main) do
+    def main
         require 'puppet/network/client'
         require 'puppet/util/ldap/connection'
 
@@ -147,7 +146,7 @@ Puppet::Application.new(:kick) do
         end
     end
 
-    preinit do
+    def preinit
         [:INT, :TERM].each do |signal|
             trap(signal) do
                 $stderr.puts "Cancelling"
@@ -165,7 +164,7 @@ Puppet::Application.new(:kick) do
         @tags = []
     end
 
-    setup do
+    def setup
         if options[:debug]
             Puppet::Util::Log.level = :debug
         else
diff --git a/lib/puppet/application/master.rb b/lib/puppet/application/master.rb
index 8f1c0cd..2433780 100644
--- a/lib/puppet/application/master.rb
+++ b/lib/puppet/application/master.rb
@@ -4,7 +4,7 @@ require 'puppet/daemon'
 require 'puppet/network/server'
 require 'puppet/network/http/rack' if Puppet.features.rack?
 
-Puppet::Application.new(:master) do
+class Puppet::Application::Master < Puppet::Application
 
     should_parse_config
 
@@ -30,7 +30,7 @@ Puppet::Application.new(:master) do
         end
     end
 
-    preinit do
+    def preinit
         trap(:INT) do
             $stderr.puts "Cancelling startup"
             exit(0)
@@ -41,17 +41,17 @@ Puppet::Application.new(:master) do
         @daemon.argv = ARGV.dup
     end
 
-    dispatch do
+    def run_command
         if options[:node]
-            :compile
+            compile
         elsif Puppet[:parseonly]
-            :parseonly
+            parseonly
         else
-            :main
+            main
         end
     end
 
-    command(:compile) do
+    def compile
         Puppet::Util::Log.newdestination :console
         raise ArgumentError, "Cannot render compiled catalogs without pson support" unless Puppet.features.pson?
         begin
@@ -67,7 +67,7 @@ Puppet::Application.new(:master) do
         exit(0)
     end
 
-    command(:parseonly) do
+    def parseonly
         begin
             Puppet::Resource::TypeCollection.new(Puppet[:environment]).perform_initial_import
         rescue => detail
@@ -77,7 +77,7 @@ Puppet::Application.new(:master) do
         exit(0)
     end
 
-    command(:main) do
+    def main
         require 'etc'
         require 'puppet/file_serving/content'
         require 'puppet/file_serving/metadata'
@@ -124,7 +124,7 @@ Puppet::Application.new(:master) do
         end
     end
 
-    setup do
+    def setup
         # Handle the logging settings.
         if options[:debug] or options[:verbose]
             if options[:debug]
diff --git a/lib/puppet/application/queue.rb b/lib/puppet/application/queue.rb
index 13fb3e1..4b3aa57 100644
--- a/lib/puppet/application/queue.rb
+++ b/lib/puppet/application/queue.rb
@@ -5,13 +5,12 @@ require 'puppet/resource/catalog'
 require 'puppet/indirector/catalog/queue'
 require 'puppet/util'
 
-Puppet::Application.new(:queue) do
-    extend Puppet::Util
+class Puppet::Application::Queue < Puppet::Application
     should_parse_config
 
     attr_accessor :daemon
 
-    preinit do
+    def preinit
         @daemon = Puppet::Daemon.new
         @daemon.argv = ARGV.dup
         Puppet::Util::Log.newdestination(:console)
@@ -41,13 +40,13 @@ Puppet::Application.new(:queue) do
     option("--debug","-d")
     option("--verbose","-v")
 
-    command(:main) do
+    def main
         Puppet.notice "Starting puppetqd %s" % Puppet.version
         Puppet::Resource::Catalog::Queue.subscribe do |catalog|
             # Once you have a Puppet::Resource::Catalog instance, calling save() on it should suffice
             # to put it through to the database via its active_record indirector (which is determined
             # by the terminus_class = :active_record setting above)
-            benchmark(:notice, "Processing queued catalog for %s" % catalog.name) do
+            Puppet::Util.benchmark(:notice, "Processing queued catalog for %s" % catalog.name) do
                 begin
                     catalog.save
                 rescue => detail
@@ -72,7 +71,7 @@ Puppet::Application.new(:queue) do
         end
     end
 
-    setup do
+    def setup
         unless Puppet.features.stomp?
             raise ArgumentError, "Could not load the 'stomp' library, which must be present for queueing to work.  You must install the required library."
         end
diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb
index 78aed95..52320e7 100644
--- a/lib/puppet/application/resource.rb
+++ b/lib/puppet/application/resource.rb
@@ -2,13 +2,13 @@ require 'puppet'
 require 'puppet/application'
 require 'facter'
 
-Puppet::Application.new(:resource) do
+class Puppet::Application::Resource < Puppet::Application
 
     should_not_parse_config
 
     attr_accessor :host, :extra_params
 
-    preinit do
+    def preinit
         @extra_params = []
         @host = nil
         Facter.loadfacts
@@ -37,7 +37,7 @@ Puppet::Application.new(:resource) do
         @extra_params << arg.to_sym
     end
 
-    command(:main) do
+    def main
         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}"
@@ -109,7 +109,7 @@ Puppet::Application.new(:resource) do
         end
     end
 
-    setup do
+    def setup
         Puppet::Util::Log.newdestination(:console)
 
         # Now parse the config
diff --git a/spec/unit/application.rb b/spec/unit/application.rb
index 87a9009..c18aa19 100755
--- a/spec/unit/application.rb
+++ b/spec/unit/application.rb
@@ -8,8 +8,8 @@ require 'getoptlong'
 
 describe Puppet::Application do
 
-    before :each do
-        @app = Puppet::Application.new(:test)
+    before do
+        @app = Class.new(Puppet::Application).new
     end
 
     it "should have a run entry-point" do
@@ -20,20 +20,21 @@ describe Puppet::Application do
         @app.should respond_to(:options)
     end
 
-    it "should create a default run_setup method" do
-        @app.should respond_to(:run_setup)
+    it "should include a default setup method" do
+        @app.should respond_to(:setup)
     end
 
-    it "should create a default run_preinit method" do
-        @app.should respond_to(:run_preinit)
+    it "should include a default preinit method" do
+        @app.should respond_to(:preinit)
     end
 
-    it "should create a default get_command method" do
-        @app.should respond_to(:get_command)
+    it "should include a default run_command method" do
+        @app.should respond_to(:run_command)
     end
 
-    it "should return :main as default get_command" do
-        @app.get_command.should == :main
+    it "should invoke main as the default" do
+        @app.expects( :main )
+        @app.run_command
     end
 
     describe 'when invoking clear!' do
@@ -170,7 +171,6 @@ describe Puppet::Application do
             ARGV.clear
 
             Puppet.settings.stubs(:optparse_addargs).returns([])
-            @app = Puppet::Application.new(:test)
         end
 
         after :each do
@@ -288,7 +288,6 @@ describe Puppet::Application do
     describe "when calling default setup" do
 
         before :each do
-            @app = Puppet::Application.new(:test)
             @app.stubs(:should_parse_config?).returns(false)
             @app.options.stubs(:[])
         end
@@ -300,7 +299,7 @@ describe Puppet::Application do
 
                 Puppet::Util::Log.expects(:level=).with(level == :verbose ? :info : :debug)
 
-                @app.run_setup
+                @app.setup
             end
         end
 
@@ -309,7 +308,7 @@ describe Puppet::Application do
 
             Puppet::Util::Log.expects(:newdestination).with(:syslog)
 
-            @app.run_setup
+            @app.setup
         end
 
     end
@@ -317,16 +316,15 @@ describe Puppet::Application do
     describe "when running" do
 
         before :each do
-            @app = Puppet::Application.new(:test)
-            @app.stubs(:run_preinit)
-            @app.stubs(:run_setup)
+            @app.stubs(:preinit)
+            @app.stubs(:setup)
             @app.stubs(:parse_options)
         end
 
-        it "should call run_preinit" do
+        it "should call preinit" do
             @app.stubs(:run_command)
 
-            @app.expects(:run_preinit)
+            @app.expects(:preinit)
 
             @app.run
         end
@@ -348,7 +346,7 @@ describe Puppet::Application do
 
         it "should parse Puppet configuration if should_parse_config is called" do
             @app.stubs(:run_command)
-            @app.should_parse_config
+            @app.class.should_parse_config
 
             Puppet.settings.expects(:parse)
 
@@ -357,7 +355,7 @@ describe Puppet::Application do
 
         it "should not parse_option if should_not_parse_config is called" do
             @app.stubs(:run_command)
-            @app.should_not_parse_config
+            @app.class.should_not_parse_config
 
             Puppet.settings.expects(:parse).never
 
@@ -373,11 +371,8 @@ describe Puppet::Application do
             @app.run
         end
 
-        it "should call the action matching what returned command" do
-            @app.stubs(:get_command).returns(:backup)
-            @app.stubs(:respond_to?).with(:backup).returns(true)
-
-            @app.expects(:backup)
+        it "should call run_command" do
+            @app.expects(:run_command)
 
             @app.run
         end
@@ -411,62 +406,23 @@ describe Puppet::Application do
 
     describe "when metaprogramming" do
 
-        before :each do
-            @app = Puppet::Application.new(:test)
-        end
-
-        it "should create a new method with command" do
-            @app.command(:test) do
-            end
-
-            @app.should respond_to(:test)
-        end
-
-        describe "when calling attr_accessor" do
-            it "should create a reader method" do
-                @app.attr_accessor(:attribute)
-
-                @app.should respond_to(:attribute)
-            end
-
-            it "should create a reader that delegates to instance_variable_get" do
-                @app.attr_accessor(:attribute)
-
-                @app.expects(:instance_variable_get).with(:@attribute)
-                @app.attribute
-            end
-
-            it "should create a writer method" do
-                @app.attr_accessor(:attribute)
-
-                @app.should respond_to(:attribute=)
-            end
-
-            it "should create a writer that delegates to instance_variable_set" do
-                @app.attr_accessor(:attribute)
-
-                @app.expects(:instance_variable_set).with(:@attribute, 1234)
-                @app.attribute=1234
-            end
-        end
-
         describe "when calling option" do
             it "should create a new method named after the option" do
-                @app.option("--test1","-t") do
+                @app.class.option("--test1","-t") do
                 end
 
                 @app.should respond_to(:handle_test1)
             end
 
             it "should transpose in option name any '-' into '_'" do
-                @app.option("--test-dashes-again","-t") do
+                @app.class.option("--test-dashes-again","-t") do
                 end
 
                 @app.should respond_to(:handle_test_dashes_again)
             end
 
             it "should create a new method called handle_test2 with option(\"--[no-]test2\")" do
-                @app.option("--[no-]test2","-t") do
+                @app.class.option("--[no-]test2","-t") do
                 end
 
                 @app.should respond_to(:handle_test2)
@@ -474,7 +430,7 @@ describe Puppet::Application do
 
             describe "when a block is passed" do
                 it "should create a new method with it" do
-                    @app.option("--[no-]test2","-t") do
+                    @app.class.option("--[no-]test2","-t") do
                         raise "I can't believe it, it works!"
                     end
 
@@ -482,66 +438,50 @@ describe Puppet::Application do
                 end
 
                 it "should declare the option to OptionParser" do
-                    @app.opt_parser.expects(:on).with { |*arg| arg[0] == "--[no-]test3" }
+                    OptionParser.any_instance.stubs(:on)
+                    OptionParser.any_instance.expects(:on).with { |*arg| arg[0] == "--[no-]test3" }
 
-                    @app.option("--[no-]test3","-t") do
+                    @app.class.option("--[no-]test3","-t") do
                     end
+
+                    @app.class.new_option_parser( @app )
                 end
 
                 it "should pass a block that calls our defined method" do
-                    @app.opt_parser.stubs(:on).yields(nil)
+                    OptionParser.any_instance.stubs(:on)
+                    OptionParser.any_instance.stubs(:on).with('--test4','-t').yields(nil)
 
                     @app.expects(:send).with(:handle_test4, nil)
 
-                    @app.option("--test4","-t") do
+                    @app.class.option("--test4","-t") do
                     end
+
+                    @app.class.new_option_parser( @app )
                 end
             end
 
             describe "when no block is given" do
                 it "should declare the option to OptionParser" do
-                    @app.opt_parser.expects(:on).with("--test4","-t")
+                    OptionParser.any_instance.stubs(:on)
+                    OptionParser.any_instance.expects(:on).with("--test4","-t")
 
-                    @app.option("--test4","-t")
+                    @app.class.option("--test4","-t")
+
+                    @app.class.new_option_parser( @app )
                 end
 
                 it "should give to OptionParser a block that adds the the value to the options array" do
-                    @app.opt_parser.stubs(:on).with("--test4","-t").yields(nil)
+                    OptionParser.any_instance.stubs(:on)
+                    OptionParser.any_instance.stubs(:on).with("--test4","-t").yields(nil)
 
                     @app.options.expects(:[]=).with(:test4,nil)
 
-                    @app.option("--test4","-t")
-                end
-            end
-        end
-
-        it "should create a method called run_setup with setup" do
-            @app.setup do
-            end
-
-            @app.should respond_to(:run_setup)
-        end
+                    @app.class.option("--test4","-t")
 
-        it "should create a method called run_preinit with preinit" do
-            @app.preinit do
-            end
-
-            @app.should respond_to(:run_preinit)
-        end
-
-        it "should create a method called handle_unknown with unknown" do
-            @app.unknown do
+                    @app.class.new_option_parser( @app )
+                end
             end
-
-            @app.should respond_to(:handle_unknown)
         end
 
-
-        it "should create a method called get_command with dispatch" do
-            @app.dispatch do
-            end
-
-            @app.should respond_to(:get_command)
-        end
     end
 end
diff --git a/spec/unit/application/agent.rb b/spec/unit/application/agent.rb
index 9c8aa11..fbcc61b 100755
--- a/spec/unit/application/agent.rb
+++ b/spec/unit/application/agent.rb
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 require 'puppet/application/agent'
 require 'puppet/network/server'
 
-describe Puppet::Application[:agent] do
+describe Puppet::Application::Agent do
     before :each do
         @puppetd = Puppet::Application[:agent]
         @puppetd.stubs(:puts)
@@ -13,7 +13,7 @@ describe Puppet::Application[:agent] do
         Puppet::Daemon.stubs(:new).returns(@daemon)
         @agent = stub_everything 'agent'
         Puppet::Agent.stubs(:new).returns(@agent)
-        @puppetd.run_preinit
+        @puppetd.preinit
         Puppet::Util::Log.stubs(:newdestination)
         Puppet::Util::Log.stubs(:level=)
 
@@ -39,7 +39,7 @@ describe Puppet::Application[:agent] do
     end
 
     it "should declare a preinit block" do
-        @puppetd.should respond_to(:run_preinit)
+        @puppetd.should respond_to(:preinit)
     end
 
     describe "in preinit" do
@@ -50,41 +50,41 @@ describe Puppet::Application[:agent] do
         it "should catch INT" do
             @puppetd.expects(:trap).with { |arg,block| arg == :INT }
 
-            @puppetd.run_preinit
+            @puppetd.preinit
         end
 
         it "should set waitforcert to 120" do
-            @puppetd.run_preinit
+            @puppetd.preinit
 
             @puppetd.options[:waitforcert].should == 120
         end
 
         it "should init client to true" do
-            @puppetd.run_preinit
+            @puppetd.preinit
 
             @puppetd.options[:client].should be_true
         end
 
         it "should init fqdn to nil" do
-            @puppetd.run_preinit
+            @puppetd.preinit
 
             @puppetd.options[:fqdn].should be_nil
         end
 
         it "should init serve to []" do
-            @puppetd.run_preinit
+            @puppetd.preinit
 
             @puppetd.options[:serve].should == []
         end
 
         it "should use MD5 as default digest algorithm" do
-            @puppetd.run_preinit
+            @puppetd.preinit
 
             @puppetd.options[:digest].should == :MD5
         end
 
         it "should not fingerprint by default" do
-            @puppetd.run_preinit
+            @puppetd.preinit
 
             @puppetd.options[:fingerprint].should be_false
         end
@@ -210,7 +210,7 @@ describe Puppet::Application[:agent] do
             it "should call setup_test" do
                 @puppetd.options.stubs(:[]).with(:test).returns(true)
                 @puppetd.expects(:setup_test)
-                @puppetd.run_setup
+                @puppetd.setup
             end
 
             it "should set options[:verbose] to true" do
@@ -233,7 +233,7 @@ describe Puppet::Application[:agent] do
 
         it "should call setup_logs" do
             @puppetd.expects(:setup_logs)
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         describe "when setting up logs" do
@@ -283,13 +283,13 @@ describe Puppet::Application[:agent] do
 
             Puppet.settings.expects(:print_configs)
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should exit after printing puppet config if asked to in Puppet config" do
             Puppet.settings.stubs(:print_configs?).returns(true)
 
-            lambda { @puppetd.run_setup }.should raise_error(SystemExit)
+            lambda { @puppetd.setup }.should raise_error(SystemExit)
         end
 
         it "should set a central log destination with --centrallogs" do
@@ -299,55 +299,55 @@ describe Puppet::Application[:agent] do
 
             Puppet::Util::Log.expects(:newdestination).with("puppet.reductivelabs.com")
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should use :main, :puppetd, and :ssl" do
             Puppet.settings.expects(:use).with(:main, :puppetd, :ssl)
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should install a remote ca location" do
             Puppet::SSL::Host.expects(:ca_location=).with(:remote)
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should install a none ca location in fingerprint mode" do
             @puppetd.options.stubs(:[]).with(:fingerprint).returns(true)
             Puppet::SSL::Host.expects(:ca_location=).with(:none)
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should tell the report handler to use REST" do
             Puppet::Transaction::Report.expects(:terminus_class=).with(:rest)
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should change the catalog_terminus setting to 'rest'" do
             Puppet.expects(:[]=).with(:catalog_terminus, :rest)
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should tell the catalog handler to use cache" do
             Puppet::Resource::Catalog.expects(:cache_class=).with(:yaml)
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should tell the facts to use facter" do
             Puppet::Node::Facts.expects(:terminus_class=).with(:facter)
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should create an agent" do
             Puppet::Agent.stubs(:new).with(Puppet::Configurer)
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         [:enable, :disable].each do |action|
@@ -355,7 +355,7 @@ describe Puppet::Application[:agent] do
                 @puppetd.options.stubs(:[]).with(action).returns(true)
                 @puppetd.expects(:enable_disable_client).with(@agent)
 
-                @puppetd.run_setup
+                @puppetd.setup
             end
         end
 
@@ -379,13 +379,13 @@ describe Puppet::Application[:agent] do
         it "should inform the daemon about our agent if :client is set to 'true'" do
             @puppetd.options.expects(:[]).with(:client).returns true
             @daemon.expects(:agent=).with(@agent)
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should not inform the daemon about our agent if :client is set to 'false'" do
             @puppetd.options[:client] = false
             @daemon.expects(:agent=).never
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should daemonize if needed" do
@@ -393,14 +393,14 @@ describe Puppet::Application[:agent] do
 
             @daemon.expects(:daemonize)
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should wait for a certificate" do
             @puppetd.options.stubs(:[]).with(:waitforcert).returns(123)
             @host.expects(:wait_for_cert).with(123)
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should not wait for a certificate in fingerprint mode" do
@@ -408,7 +408,7 @@ describe Puppet::Application[:agent] do
             @puppetd.options.stubs(:[]).with(:waitforcert).returns(123)
             @host.expects(:wait_for_cert).never
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         it "should setup listen if told to and not onetime" do
@@ -417,7 +417,7 @@ describe Puppet::Application[:agent] do
 
             @puppetd.expects(:setup_listen)
 
-            @puppetd.run_setup
+            @puppetd.setup
         end
 
         describe "when setting up listen" do
@@ -475,19 +475,22 @@ describe Puppet::Application[:agent] do
         it "should dispatch to fingerprint if --fingerprint is used" do
             @puppetd.options.stubs(:[]).with(:fingerprint).returns(true)
 
-            @puppetd.get_command.should == :fingerprint
+            @puppetd.stubs(:fingerprint)
+            @puppetd.run_command
         end
 
         it "should dispatch to onetime if --onetime is used" do
             @puppetd.options.stubs(:[]).with(:onetime).returns(true)
 
-            @puppetd.get_command.should == :onetime
+            @puppetd.stubs(:onetime)
+            @puppetd.run_command
         end
 
         it "should dispatch to main if --onetime and --fingerprint are not used" do
             @puppetd.options.stubs(:[]).with(:onetime).returns(false)
 
-            @puppetd.get_command.should == :main
+            @puppetd.stubs(:main)
+            @puppetd.run_command
         end
 
         describe "with --onetime" do
diff --git a/spec/unit/application/apply.rb b/spec/unit/application/apply.rb
index 6fdeebf..10202e1 100755
--- a/spec/unit/application/apply.rb
+++ b/spec/unit/application/apply.rb
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 
 require 'puppet/application/apply'
 
-describe "Puppet" do
+describe Puppet::Application::Apply do
     before :each do
         @apply = Puppet::Application[:apply]
         Puppet::Util::Log.stubs(:newdestination)
@@ -67,19 +67,19 @@ describe "Puppet" do
 
             Puppet.expects(:[]=).with(:show_diff, true)
 
-            @apply.run_setup
+            @apply.setup
         end
 
         it "should set console as the log destination if logdest option wasn't provided" do
             Puppet::Log.expects(:newdestination).with(:console)
 
-            @apply.run_setup
+            @apply.setup
         end
 
         it "should set INT trap" do
             @apply.expects(:trap).with(:INT)
 
-            @apply.run_setup
+            @apply.setup
         end
 
         it "should set log level to debug if --debug was passed" do
@@ -87,7 +87,7 @@ describe "Puppet" do
 
             Puppet::Log.expects(:level=).with(:debug)
 
-            @apply.run_setup
+            @apply.setup
         end
 
         it "should set log level to info if --verbose was passed" do
@@ -95,7 +95,7 @@ describe "Puppet" do
 
             Puppet::Log.expects(:level=).with(:info)
 
-            @apply.run_setup
+            @apply.setup
         end
 
         it "should print puppet config if asked to in Puppet config" do
@@ -104,13 +104,13 @@ describe "Puppet" do
 
             Puppet.settings.expects(:print_configs)
 
-            @apply.run_setup
+            @apply.setup
         end
 
         it "should exit after printing puppet config if asked to in Puppet config" do
             Puppet.settings.stubs(:print_configs?).returns(true)
 
-            lambda { @apply.run_setup }.should raise_error(SystemExit)
+            lambda { @apply.setup }.should raise_error(SystemExit)
         end
 
     end
@@ -121,20 +121,23 @@ describe "Puppet" do
             @apply.stubs(:options).returns({})
             Puppet.stubs(:[]).with(:parseonly).returns(true)
 
-            @apply.get_command.should == :parseonly
+            @apply.expects(:parseonly)
+            @apply.run_command
         end
 
         it "should dispatch to 'apply' if it was called with 'apply'" do
             @apply.options[:catalog] = "foo"
 
-            @apply.get_command.should == :apply
+            @apply.expects(:apply)
+            @apply.run_command
         end
 
         it "should dispatch to main if parseonly is not set" do
             @apply.stubs(:options).returns({})
             Puppet.stubs(:[]).with(:parseonly).returns(false)
 
-            @apply.get_command.should == :main
+            @apply.expects(:main)
+            @apply.run_command
         end
 
         describe "the parseonly command" do
diff --git a/spec/unit/application/cert.rb b/spec/unit/application/cert.rb
index 8757cf3..3fb2f1e 100644
--- a/spec/unit/application/cert.rb
+++ b/spec/unit/application/cert.rb
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 
 require 'puppet/application/cert'
 
-describe "PuppetCA" do
+describe Puppet::Application::Cert do
     before :each do
         @cert_app = Puppet::Application[:cert]
         Puppet::Util::Log.stubs(:newdestination)
@@ -74,7 +74,7 @@ describe "PuppetCA" do
         it "should set console as the log destination" do
             Puppet::Log.expects(:newdestination).with(:console)
 
-            @cert_app.run_setup
+            @cert_app.setup
         end
 
         it "should print puppet config if asked to in Puppet config" do
@@ -83,25 +83,25 @@ describe "PuppetCA" do
 
             Puppet.settings.expects(:print_configs)
 
-            @cert_app.run_setup
+            @cert_app.setup
         end
 
         it "should exit after printing puppet config if asked to in Puppet config" do
             Puppet.settings.stubs(:print_configs?).returns(true)
 
-            lambda { @cert_app.run_setup }.should raise_error(SystemExit)
+            lambda { @cert_app.setup }.should raise_error(SystemExit)
         end
 
         it "should set the CA location to 'only'" do
             Puppet::SSL::Host.expects(:ca_location=).with(:only)
 
-            @cert_app.run_setup
+            @cert_app.setup
         end
 
         it "should create a new certificate authority" do
             Puppet::SSL::CertificateAuthority.expects(:new)
 
-            @cert_app.run_setup
+            @cert_app.setup
         end
     end
 
diff --git a/spec/unit/application/describe.rb b/spec/unit/application/describe.rb
index fd0c5e0..002cdb7 100755
--- a/spec/unit/application/describe.rb
+++ b/spec/unit/application/describe.rb
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 
 require 'puppet/application/describe'
 
-describe Puppet::Application[:describe] do
+describe Puppet::Application::Describe do
     before :each do
         @describe = Puppet::Application[:describe]
     end
@@ -18,7 +18,7 @@ describe Puppet::Application[:describe] do
     end
 
     it "should declare a preinit block" do
-        @describe.should respond_to(:run_preinit)
+        @describe.should respond_to(:preinit)
     end
 
     [:providers,:list,:meta].each do |option|
@@ -35,7 +35,7 @@ describe Puppet::Application[:describe] do
 
     describe "in preinit" do
         it "should set options[:parameteers] to true" do
-            @describe.run_preinit
+            @describe.preinit
 
             @describe.options[:parameters].should be_true
         end
@@ -51,8 +51,8 @@ describe Puppet::Application[:describe] do
 
     describe "during setup" do
         it "should collect arguments in options[:types]" do
-            Puppet::Util::CommandLine.stubs(:args).returns(['1','2'])
-            @describe.run_setup
+            @describe.command_line.stubs(:args).returns(['1','2'])
+            @describe.setup
 
             @describe.options[:types].should == ['1','2']
         end
diff --git a/spec/unit/application/doc.rb b/spec/unit/application/doc.rb
index 1856128..3bda25f 100755
--- a/spec/unit/application/doc.rb
+++ b/spec/unit/application/doc.rb
@@ -4,11 +4,11 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 
 require 'puppet/application/doc'
 
-describe "doc" do
+describe Puppet::Application::Doc do
     before :each do
         @doc = Puppet::Application[:doc]
         @doc.stubs(:puts)
-        @doc.run_preinit
+        @doc.preinit
         Puppet::Util::Log.stubs(:newdestination)
         Puppet::Util::Log.stubs(:level=)
     end
@@ -34,24 +34,24 @@ describe "doc" do
     end
 
     it "should declare a preinit block" do
-        @doc.should respond_to(:run_preinit)
+        @doc.should respond_to(:preinit)
     end
 
     describe "in preinit" do
         it "should set references to []" do
-            @doc.run_preinit
+            @doc.preinit
 
             @doc.options[:references].should == []
         end
 
         it "should init mode to text" do
-            @doc.run_preinit
+            @doc.preinit
 
             @doc.options[:mode].should == :text
         end
 
         it "should init format to to_rest" do
-            @doc.run_preinit
+            @doc.preinit
 
             @doc.options[:format].should == :to_rest
         end
@@ -137,7 +137,7 @@ describe "doc" do
 
             @doc.options.expects(:[]=).with(:mode,:rdoc)
 
-            @doc.run_setup
+            @doc.setup
         end
 
         it "should call setup_rdoc in rdoc mode" do
@@ -145,7 +145,7 @@ describe "doc" do
 
             @doc.expects(:setup_rdoc)
 
-            @doc.run_setup
+            @doc.setup
         end
 
         it "should call setup_reference if not rdoc" do
@@ -153,7 +153,7 @@ describe "doc" do
 
             @doc.expects(:setup_reference)
 
-            @doc.run_setup
+            @doc.setup
         end
 
         describe "in non-rdoc mode" do
diff --git a/spec/unit/application/filebucket.rb b/spec/unit/application/filebucket.rb
index 37cc939..68af45c 100644
--- a/spec/unit/application/filebucket.rb
+++ b/spec/unit/application/filebucket.rb
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 
 require 'puppet/application/filebucket'
 
-describe Puppet::Application[:filebucket] do
+describe Puppet::Application::Filebucket do
     before :each do
         @filebucket = Puppet::Application[:filebucket]
     end
@@ -51,13 +51,13 @@ describe Puppet::Application[:filebucket] do
         it "should set console as the log destination" do
             Puppet::Log.expects(:newdestination).with(:console)
 
-            @filebucket.run_setup
+            @filebucket.setup
         end
 
         it "should trap INT" do
             @filebucket.expects(:trap).with(:INT)
 
-            @filebucket.run_setup
+            @filebucket.setup
         end
 
         it "should set log level to debug if --debug was passed" do
@@ -65,7 +65,7 @@ describe Puppet::Application[:filebucket] do
 
             Puppet::Log.expects(:level=).with(:debug)
 
-            @filebucket.run_setup
+            @filebucket.setup
         end
 
         it "should set log level to info if --verbose was passed" do
@@ -73,13 +73,13 @@ describe Puppet::Application[:filebucket] do
 
             Puppet::Log.expects(:level=).with(:info)
 
-            @filebucket.run_setup
+            @filebucket.setup
         end
 
         it "should Parse puppet config" do
             Puppet.expects(:parse_config)
 
-            @filebucket.run_setup
+            @filebucket.setup
         end
 
         it "should print puppet config if asked to in Puppet config" do
@@ -88,13 +88,13 @@ describe Puppet::Application[:filebucket] do
 
             Puppet.settings.expects(:print_configs)
 
-            @filebucket.run_setup
+            @filebucket.setup
         end
 
         it "should exit after printing puppet config if asked to in Puppet config" do
             Puppet.settings.stubs(:print_configs?).returns(true)
 
-            lambda { @filebucket.run_setup }.should raise_error(SystemExit)
+            lambda { @filebucket.setup }.should raise_error(SystemExit)
         end
 
         describe "with local bucket" do
@@ -108,7 +108,7 @@ describe Puppet::Application[:filebucket] do
 
                 Puppet::FileBucket::Dipper.expects(:new).with { |h| h[:Path] == "path" }
 
-                @filebucket.run_setup
+                @filebucket.setup
             end
 
             it "should create a local Dipper with the given bucket" do
@@ -116,7 +116,7 @@ describe Puppet::Application[:filebucket] do
 
                 Puppet::FileBucket::Dipper.expects(:new).with { |h| h[:Path] == "path" }
 
-                @filebucket.run_setup
+                @filebucket.setup
             end
 
         end
@@ -128,7 +128,7 @@ describe Puppet::Application[:filebucket] do
 
                 Puppet::FileBucket::Dipper.expects(:new).with { |h| h[:Server] == "puppet.reductivelabs.com" }
 
-                @filebucket.run_setup
+                @filebucket.setup
             end
 
         end
@@ -148,19 +148,22 @@ describe Puppet::Application[:filebucket] do
             @client = stub 'client'
             Puppet::FileBucket::Dipper.stubs(:new).returns(@client)
 
-            @filebucket.run_setup
+            @filebucket.setup
         end
 
         it "should use the first non-option parameter as the dispatch" do
             Puppet::Util::CommandLine.stubs(:args).returns([:get])
 
-            @filebucket.get_command.should == :get
+            @filebucket.expects(:get)
+
+            @filebucket.run_command
         end
 
         describe "the command get" do
 
             before :each do
                 @filebucket.stubs(:print)
+                @filebucket.stubs(:args).returns([])
             end
 
             it "should call the client getfile method" do
diff --git a/spec/unit/application/kick.rb b/spec/unit/application/kick.rb
index b617537..c1b7806 100755
--- a/spec/unit/application/kick.rb
+++ b/spec/unit/application/kick.rb
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 require 'puppet/util/ldap/connection'
 require 'puppet/application/kick'
 
-describe Puppet::Application[:kick] do
+describe Puppet::Application::Kick do
     before :each do
         Puppet::Util::Ldap::Connection.stubs(:new).returns(stub_everything)
         @kick = Puppet::Application[:kick]
@@ -14,7 +14,6 @@ describe Puppet::Application[:kick] do
     end
 
     it "should ask Puppet::Application to not parse Puppet configuration file" do
-        p @kick.object_id
         @kick.should_parse_config?.should be_false
     end
 
@@ -27,7 +26,7 @@ describe Puppet::Application[:kick] do
     end
 
     it "should declare a preinit block" do
-        @kick.should respond_to(:run_preinit)
+        @kick.should respond_to(:preinit)
     end
 
     describe "during preinit" do
@@ -38,35 +37,35 @@ describe Puppet::Application[:kick] do
         it "should catch INT and TERM" do
             @kick.stubs(:trap).with { |arg,block| arg == :INT or arg == :TERM }
 
-            @kick.run_preinit
+            @kick.preinit
         end
 
         it "should set parallel option to 1" do
-            @kick.run_preinit
+            @kick.preinit
 
             @kick.options[:parallel].should == 1
         end
 
         it "should set verbose by default" do
-            @kick.run_preinit
+            @kick.preinit
 
             @kick.options[:verbose].should be_true
         end
 
         it "should set fqdn by default" do
-            @kick.run_preinit
+            @kick.preinit
 
             @kick.options[:fqdn].should be_true
         end
 
         it "should set ignoreschedules to 'false'" do
-            @kick.run_preinit
+            @kick.preinit
 
             @kick.options[:ignoreschedules].should be_false
         end
 
         it "should set foreground to 'false'" do
-            @kick.run_preinit
+            @kick.preinit
 
             @kick.options[:foreground].should be_false
         end
@@ -74,6 +73,10 @@ describe Puppet::Application[:kick] do
 
     describe "when applying options" do
 
+        before do
+            @kick.preinit
+        end
+
         [:all, :foreground, :debug, :ping, :test].each do |option|
             it "should declare handle_#{option} method" do
                 @kick.should respond_to("handle_#{option}".to_sym)
@@ -123,7 +126,7 @@ describe Puppet::Application[:kick] do
 
             Puppet::Log.expects(:level=).with(:debug)
 
-            @kick.run_setup
+            @kick.setup
         end
 
         it "should set log level to info if --verbose was passed" do
@@ -131,13 +134,13 @@ describe Puppet::Application[:kick] do
 
             Puppet::Log.expects(:level=).with(:info)
 
-            @kick.run_setup
+            @kick.setup
         end
 
         it "should Parse puppet config" do
             Puppet.expects(:parse_config)
 
-            @kick.run_setup
+            @kick.setup
         end
 
         describe "when using the ldap node terminus" do
@@ -152,7 +155,7 @@ describe Puppet::Application[:kick] do
 
                 Puppet::Node.expects(:search).with("whatever",:fqdn => :something).returns([])
 
-                @kick.run_setup
+                @kick.setup
             end
 
             it "should search for all nodes if --all" do
@@ -161,7 +164,7 @@ describe Puppet::Application[:kick] do
 
                 Puppet::Node.expects(:search).with("whatever",:fqdn => nil).returns([])
 
-                @kick.run_setup
+                @kick.setup
             end
 
             it "should search for nodes including given classes" do
@@ -171,7 +174,7 @@ describe Puppet::Application[:kick] do
 
                 Puppet::Node.expects(:search).with("whatever", :class => "class", :fqdn => nil).returns([])
 
-                @kick.run_setup
+                @kick.setup
             end
         end
 
@@ -182,7 +185,7 @@ describe Puppet::Application[:kick] do
 
                 @kick.expects(:exit).with(24)
 
-                @kick.run_setup
+                @kick.setup
             end
         end
     end
@@ -195,13 +198,15 @@ describe Puppet::Application[:kick] do
         it "should dispatch to test if --test is used" do
             @kick.options.stubs(:[]).with(:test).returns(true)
 
-            @kick.get_command.should == :test
+            @kick.expects(:test)
+            @kick.run_command
         end
 
         it "should dispatch to main if --test is not used" do
             @kick.options.stubs(:[]).with(:test).returns(false)
 
-            @kick.get_command.should == :main
+            @kick.expects(:main)
+            @kick.run_command
         end
 
         describe "the test command" do
@@ -218,8 +223,12 @@ describe Puppet::Application[:kick] do
                 @kick.options.stubs(:[]).with(:ping).returns(false)
                 @kick.options.stubs(:[]).with(:ignoreschedules).returns(false)
                 @kick.options.stubs(:[]).with(:foreground).returns(false)
+                @kick.options.stubs(:[]).with(:debug).returns(false)
                 @kick.stubs(:print)
                 @kick.stubs(:exit)
+                @kick.preinit
+                @kick.parse_options
+                @kick.setup
                 $stderr.stubs(:puts)
             end
 
@@ -251,6 +260,7 @@ describe Puppet::Application[:kick] do
                     options = {
                         :background => true, :ignoreschedules => false, :tags => []
                     }
+                    @kick.preinit
                     @agent_run = Puppet::Run.new( options.dup )
                     @agent_run.stubs(:status).returns("success")
 
diff --git a/spec/unit/application/master.rb b/spec/unit/application/master.rb
index b3c1a72..2672fdb 100644
--- a/spec/unit/application/master.rb
+++ b/spec/unit/application/master.rb
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 
 require 'puppet/application/master'
 
-describe "PuppetMaster" do
+describe Puppet::Application::Master do
     before :each do
         @master = Puppet::Application[:master]
         @daemon = stub_everything 'daemon'
@@ -37,7 +37,7 @@ describe "PuppetMaster" do
     end
 
     it "should declare a preinit block" do
-        @master.should respond_to(:run_preinit)
+        @master.should respond_to(:preinit)
     end
 
     describe "during preinit" do
@@ -48,13 +48,13 @@ describe "PuppetMaster" do
         it "should catch INT" do
             @master.stubs(:trap).with { |arg,block| arg == :INT }
 
-            @master.run_preinit
+            @master.preinit
         end
 
         it "should create a Puppet Daemon" do
             Puppet::Daemon.expects(:new).returns(@daemon)
 
-            @master.run_preinit
+            @master.preinit
         end
 
         it "should give ARGV to the Daemon" do
@@ -62,7 +62,7 @@ describe "PuppetMaster" do
             ARGV.stubs(:dup).returns(argv)
             @daemon.expects(:argv=).with(argv)
 
-            @master.run_preinit
+            @master.preinit
         end
 
     end
@@ -128,7 +128,7 @@ describe "PuppetMaster" do
 
             Puppet::Log.expects(:level=).with(:debug)
 
-            @master.run_setup
+            @master.setup
         end
 
         it "should set log level to info if --verbose was passed" do
@@ -136,7 +136,7 @@ describe "PuppetMaster" do
 
             Puppet::Log.expects(:level=).with(:info)
 
-            @master.run_setup
+            @master.setup
         end
 
         it "should set console as the log destination if no --logdest and --daemonize" do
@@ -144,13 +144,13 @@ describe "PuppetMaster" do
 
             Puppet::Log.expects(:newdestination).with(:syslog)
 
-            @master.run_setup
+            @master.setup
         end
 
         it "should set syslog as the log destination if no --logdest and not --daemonize" do
             Puppet::Log.expects(:newdestination).with(:syslog)
 
-            @master.run_setup
+            @master.setup
         end
 
         it "should set syslog as the log destination if --rack" do
@@ -158,7 +158,7 @@ describe "PuppetMaster" do
 
             Puppet::Log.expects(:newdestination).with(:syslog)
 
-            @master.run_setup
+            @master.setup
         end
 
         it "should print puppet config if asked to in Puppet config" do
@@ -167,31 +167,31 @@ describe "PuppetMaster" do
 
             Puppet.settings.expects(:print_configs)
 
-            @master.run_setup
+            @master.setup
         end
 
         it "should exit after printing puppet config if asked to in Puppet config" do
             Puppet.settings.stubs(:print_configs?).returns(true)
 
-            lambda { @master.run_setup }.should raise_error(SystemExit)
+            lambda { @master.setup }.should raise_error(SystemExit)
         end
 
         it "should tell Puppet.settings to use :main,:ssl and :puppetmasterd category" do
             Puppet.settings.expects(:use).with(:main,:puppetmasterd,:ssl)
 
-            @master.run_setup
+            @master.setup
         end
 
         it "should set node facst terminus to yaml" do
             Puppet::Node::Facts.expects(:terminus_class=).with(:yaml)
 
-            @master.run_setup
+            @master.setup
         end
 
         it "should cache class in yaml" do
             Puppet::Node.expects(:cache_class=).with(:yaml)
 
-            @master.run_setup
+            @master.setup
         end
 
         describe "with no ca" do
@@ -199,7 +199,7 @@ describe "PuppetMaster" do
             it "should set the ca_location to none" do
                 Puppet::SSL::Host.expects(:ca_location=).with(:none)
 
-                @master.run_setup
+                @master.setup
             end
 
         end
@@ -213,19 +213,19 @@ describe "PuppetMaster" do
             it "should set the ca_location to local" do
                 Puppet::SSL::Host.expects(:ca_location=).with(:local)
 
-                @master.run_setup
+                @master.setup
             end
 
             it "should tell Puppet.settings to use :ca category" do
                 Puppet.settings.expects(:use).with(:ca)
 
-                @master.run_setup
+                @master.setup
             end
 
             it "should instantiate the CertificateAuthority singleton" do
                 Puppet::SSL::CertificateAuthority.expects(:instance)
 
-                @master.run_setup
+                @master.setup
             end
 
 
@@ -234,24 +234,30 @@ describe "PuppetMaster" do
     end
 
     describe "when running" do
+        before do
+            @master.preinit
+        end
 
         it "should dispatch to parseonly if parseonly is set" do
             Puppet.stubs(:[]).with(:parseonly).returns(true)
             @master.options[:node] = nil
 
-            @master.get_command.should == :parseonly
+            @master.expects(:parseonly)
+            @master.run_command
         end
 
         it "should dispatch to compile if called with --compile" do
             @master.options[:node] = "foo"
-            @master.get_command.should == :compile
+            @master.expects(:compile)
+            @master.run_command
         end
 
         it "should dispatch to main if parseonly is not set" do
             Puppet.stubs(:[]).with(:parseonly).returns(false)
             @master.options[:node] = nil
 
-            @master.get_command.should == :main
+            @master.expects(:main)
+            @master.run_command
         end
 
 
@@ -335,7 +341,7 @@ describe "PuppetMaster" do
 
         describe "the main command" do
             before :each do
-                @master.run_preinit
+                @master.preinit
                 @server = stub_everything 'server'
                 Puppet::Network::Server.stubs(:new).returns(@server)
                 @app = stub_everything 'app'
diff --git a/spec/unit/application/queue.rb b/spec/unit/application/queue.rb
index e761aec..9f5b6c2 100755
--- a/spec/unit/application/queue.rb
+++ b/spec/unit/application/queue.rb
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 
 require 'puppet/application/queue'
 
-describe "queue" do
+describe Puppet::Application::Queue do
     before :each do
         @queue = Puppet::Application[:queue]
         @queue.stubs(:puts)
@@ -24,7 +24,7 @@ describe "queue" do
     end
 
     it "should declare a preinit block" do
-        @queue.should respond_to(:run_preinit)
+        @queue.should respond_to(:preinit)
     end
 
     describe "in preinit" do
@@ -35,17 +35,17 @@ describe "queue" do
         it "should catch INT" do
             @queue.expects(:trap).with { |arg,block| arg == :INT }
 
-            @queue.run_preinit
+            @queue.preinit
         end
 
         it "should init :verbose to false" do
-            @queue.run_preinit
+            @queue.preinit
 
             @queue.options[:verbose].should be_false
         end
 
         it "should init :debug to false" do
-            @queue.run_preinit
+            @queue.preinit
 
             @queue.options[:debug].should be_false
         end
@@ -55,7 +55,7 @@ describe "queue" do
             daemon = mock("daemon")
             daemon.expects(:argv=).with("eh")
             Puppet::Daemon.expects(:new).returns daemon
-            @queue.run_preinit
+            @queue.preinit
         end
     end
 
@@ -87,7 +87,7 @@ describe "queue" do
 
         it "should fail if the stomp feature is missing" do
             Puppet.features.expects(:stomp?).returns false
-            lambda { @queue.run_setup }.should raise_error(ArgumentError)
+            lambda { @queue.setup }.should raise_error(ArgumentError)
         end
 
         it "should print puppet config if asked to in Puppet config" do
@@ -96,18 +96,18 @@ describe "queue" do
 
             Puppet.settings.expects(:print_configs)
 
-            @queue.run_setup
+            @queue.setup
         end
 
         it "should exit after printing puppet config if asked to in Puppet config" do
             Puppet.settings.stubs(:print_configs?).returns(true)
 
-            lambda { @queue.run_setup }.should raise_error(SystemExit)
+            lambda { @queue.setup }.should raise_error(SystemExit)
         end
 
         it "should call setup_logs" do
             @queue.expects(:setup_logs)
-            @queue.run_setup
+            @queue.setup
         end
 
         describe "when setting up logs" do
@@ -145,7 +145,7 @@ describe "queue" do
         it "should configure the Catalog class to use ActiveRecord" do
             Puppet::Resource::Catalog.expects(:terminus_class=).with(:active_record)
 
-            @queue.run_setup
+            @queue.setup
         end
 
         it "should daemonize if needed" do
@@ -153,7 +153,7 @@ describe "queue" do
 
             @queue.daemon.expects(:daemonize)
 
-            @queue.run_setup
+            @queue.setup
         end
     end
 
diff --git a/spec/unit/application/resource.rb b/spec/unit/application/resource.rb
index 90fd3cc..2e90cc2 100755
--- a/spec/unit/application/resource.rb
+++ b/spec/unit/application/resource.rb
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
 
 require 'puppet/application/resource'
 
-describe "resource" do
+describe Puppet::Application::Resource do
     before :each do
         @resource = Puppet::Application[:resource]
         Puppet::Util::Log.stubs(:newdestination)
@@ -33,25 +33,25 @@ describe "resource" do
     end
 
     it "should declare a preinit block" do
-        @resource.should respond_to(:run_preinit)
+        @resource.should respond_to(:preinit)
     end
 
     describe "in preinit" do
         it "should set hosts to nil" do
-            @resource.run_preinit
+            @resource.preinit
 
             @resource.host.should be_nil
         end
 
         it "should init extra_params to empty array" do
-            @resource.run_preinit
+            @resource.preinit
 
             @resource.extra_params.should == []
         end
 
         it "should load Facter facts" do
           Facter.expects(:loadfacts).once
-          @resource.run_preinit
+          @resource.preinit
         end
     end
 
@@ -104,7 +104,7 @@ describe "resource" do
         it "should set console as the log destination" do
             Puppet::Log.expects(:newdestination).with(:console)
 
-            @resource.run_setup
+            @resource.setup
         end
 
         it "should set log level to debug if --debug was passed" do
@@ -112,7 +112,7 @@ describe "resource" do
 
             Puppet::Log.expects(:level=).with(:debug)
 
-            @resource.run_setup
+            @resource.setup
         end
 
         it "should set log level to info if --verbose was passed" do
@@ -121,13 +121,13 @@ describe "resource" do
 
             Puppet::Log.expects(:level=).with(:info)
 
-            @resource.run_setup
+            @resource.setup
         end
 
         it "should Parse puppet config" do
             Puppet.expects(:parse_config)
 
-            @resource.run_setup
+            @resource.setup
         end
     end
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list