Signed-off-by: Brice Figureau <[email protected]>
---
 bin/puppetca                       |   86 +-----------------------------------
 lib/puppet/application/puppetca.rb |   68 ++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 84 deletions(-)
 create mode 100644 lib/puppet/application/puppetca.rb

diff --git a/bin/puppetca b/bin/puppetca
index 81e1439..b5d3707 100755
--- a/bin/puppetca
+++ b/bin/puppetca
@@ -97,8 +97,7 @@
 # Licensed under the GNU Public License
 
 require 'puppet'
-require 'puppet/ssl/certificate_authority'
-require 'getoptlong'
+require 'puppet/application/puppetca'
 
 options = [
     [ "--all",      "-a",  GetoptLong::NO_ARGUMENT ],
@@ -115,85 +114,4 @@ options = [
     [ "--verbose",  "-v",  GetoptLong::NO_ARGUMENT ]
 ]
 
-# Add all of the config parameters as valid options.
-Puppet.settings.addargs(options)
-
-result = GetoptLong.new(*options)
-
-modes = Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS
-
-all = false
-mode = nil
-
-begin
-    result.each { |opt,arg|
-        case opt
-            when "--clean"
-                mode = :destroy
-            when "--all"
-                all = true
-            when "--debug"
-                Puppet::Util::Log.level = :debug
-            when "--help"
-                if Puppet.features.usage?
-                    RDoc::usage && exit
-                else
-                    puts "No help available unless you have RDoc::usage 
installed"
-                    exit
-                end
-            when "--version"
-                puts "%s" % Puppet.version
-                exit
-            when "--verbose"
-                Puppet::Util::Log.level = :info
-            else
-                tmp = opt.sub("--", '').to_sym
-                if modes.include?(tmp)
-                    mode = tmp
-                else
-                    Puppet.settings.handlearg(opt, arg)
-                end
-        end
-    }
-rescue GetoptLong::InvalidOption => detail
-    $stderr.puts "Try '#{$0} --help'"
-    exit(1)
-end
-
-# Now parse the config
-Puppet.parse_config
-
-if Puppet.settings.print_configs?
-    exit(Puppet.settings.print_configs ? 0 : 1)
-end
-
-Puppet::Util::Log.newdestination :console
-
-Puppet::SSL::Host.ca_location = :local
-
-begin
-    ca = Puppet::SSL::CertificateAuthority.new
-rescue => detail
-    puts detail.backtrace if Puppet[:trace]
-    puts detail.to_s
-    exit(23)
-end
-
-unless mode
-    $stderr.puts "You must specify a mode; see the output from --help"
-    exit(12)
-end
-
-if all
-    hosts = :all
-else
-    hosts = ARGV.collect { |h| h.downcase }
-end
-
-begin
-    ca.apply(mode, :to => hosts)
-rescue => detail
-    puts detail.backtrace if Puppet[:trace]
-    puts detail.to_s
-    exit(24)
-end
+Puppet::Application::PuppetCA.new(options).run
\ No newline at end of file
diff --git a/lib/puppet/application/puppetca.rb 
b/lib/puppet/application/puppetca.rb
new file mode 100644
index 0000000..cffc110
--- /dev/null
+++ b/lib/puppet/application/puppetca.rb
@@ -0,0 +1,68 @@
+require 'puppet'
+require 'puppet/application'
+require 'puppet/ssl/certificate_authority'
+
+class Puppet::Application::PuppetCA < Puppet::Application
+
+    def main
+        if @all
+            hosts = :all
+        else
+            hosts = ARGV.collect { |h| h.downcase }
+        end
+
+        begin
+            @ca.apply(@mode, :to => hosts)
+        rescue => detail
+            puts detail.backtrace if Puppet[:trace]
+            puts detail.to_s
+            exit(24)
+        end
+    end
+
+    def setup
+        @all = false
+        @mode = nil
+
+        # Now parse the config
+        Puppet.parse_config
+
+        if Puppet.settings.print_configs?
+            exit(Puppet.settings.print_configs ? 0 : 1)
+        end
+
+        Puppet::Util::Log.newdestination :console
+
+        Puppet::SSL::Host.ca_location = :local
+
+        begin
+            @ca = Puppet::SSL::CertificateAuthority.new
+        rescue => detail
+            puts detail.backtrace if Puppet[:trace]
+            puts detail.to_s
+            exit(23)
+        end
+    end
+
+    def handle_unknown(opt, arg)
+        modes = Puppet::SSL::CertificateAuthority::Interface::INTERFACE_METHODS
+        tmp = opt.sub("--", '').to_sym
+        @mode = modes.include?(tmp) ? tmp : nil
+    end
+
+    def handle_clean(arg)
+        @mode = :destroy
+    end
+
+    def handle_all(arg)
+        @all = true
+    end
+
+    def handle_verbose(arg)
+        Puppet::Util::Log.level = :info
+    end
+
+    def handle_debug(arg)
+        Puppet::Util::Log.level = :debug
+    end
+end
\ No newline at end of file
-- 
1.6.0.2


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to