Signed-off-by: Brice Figureau <brice-pup...@daysofwonder.com>
---
 bin/filebucket                       |  108 +--------------------------------
 lib/puppet/application/filebucket.rb |   80 +++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 104 deletions(-)
 create mode 100644 lib/puppet/application/filebucket.rb

diff --git a/bin/filebucket b/bin/filebucket
index 17e01ed..ad434f0 100755
--- a/bin/filebucket
+++ b/bin/filebucket
@@ -95,8 +95,8 @@
 # Licensed under the GNU Public License
 
 require 'puppet'
-require 'puppet/network/client'
-require 'getoptlong'
+require 'puppet/application'
+require 'puppet/application/filebucket'
 
 options = [
     [ "--bucket",   "-b",                      GetoptLong::REQUIRED_ARGUMENT ],
@@ -108,105 +108,5 @@ options = [
     [ "--version",  "-V",           GetoptLong::NO_ARGUMENT ]
 ]
 
-# Add all of the config parameters as valid options.
-Puppet.settings.addargs(options)
-
-result = GetoptLong.new(*options)
-
-options = {}
-
-begin
-    result.each { |opt,arg|
-        case opt
-            when "--version"
-                puts "%s" % Puppet.version
-                exit
-            when "--help"
-                if Puppet.features.usage?
-                    RDoc::usage && exit
-                else
-                    puts "No help available unless you have RDoc::usage 
installed"
-                    exit
-                end
-            when "--bucket"
-                options[:bucket] = arg
-            when "--verbose"
-                options[:verbose] = true
-            when "--debug"
-                options[:debug] = true
-            when "--local"
-                options[:local] = true
-            when "--remote"
-                options[:remote] = true
-            else
-                Puppet.settings.handlearg(opt, arg)
-        end
-    }
-rescue GetoptLong::InvalidOption => detail
-    $stderr.puts "Try '#{$0} --help'"
-    exit(1)
-end
-
-Puppet::Log.newdestination(:console)
-
-client = nil
-server = nil
-
-Puppet.settraps
-
-if options[:debug]
-    Puppet::Log.level = :debug
-elsif options[:verbose]
-    Puppet::Log.level = :info
-end
-
-# Now parse the config
-Puppet.parse_config
-
-if Puppet.settings.print_configs?
-        exit(Puppet.settings.print_configs ? 0 : 1)
-end
-
-begin
-    if options[:local] or options[:bucket]
-        path = options[:bucket] || Puppet[:bucketdir]
-        client = Puppet::Network::Client.dipper.new(:Path => path)
-    else
-        require 'puppet/network/handler'
-        client = Puppet::Network::Client.dipper.new(:Server => Puppet[:server])
-    end
-rescue => detail
-    $stderr.puts detail
-    if Puppet[:trace]
-        puts detail.backtrace
-    end
-    exit(1)
-end
-
-mode = ARGV.shift
-case mode
-when "get":
-    md5 = ARGV.shift
-    out = client.getfile(md5)
-    print out
-when "backup":
-    ARGV.each do |file|
-        unless FileTest.exists?(file)
-            $stderr.puts "%s: no such file" % file
-            next
-        end
-        unless FileTest.readable?(file)
-            $stderr.puts "%s: cannot read file" % file
-            next
-        end
-        md5 = client.backup(file)
-        puts "%s: %s" % [file, md5]
-    end
-when "restore":
-    file = ARGV.shift
-    md5 = ARGV.shift
-    client.restore(file, md5)
-else
-    raise "Invalid mode %s" % mode
-end
-
+# launch the filebucket
+Puppet::Application::Filebucket.new(options).run
\ No newline at end of file
diff --git a/lib/puppet/application/filebucket.rb 
b/lib/puppet/application/filebucket.rb
new file mode 100644
index 0000000..0c994d1
--- /dev/null
+++ b/lib/puppet/application/filebucket.rb
@@ -0,0 +1,80 @@
+require 'puppet'
+require 'puppet/application'
+require 'puppet/network/client'
+
+class Puppet::Application::Filebucket < Puppet::Application
+
+    def command
+        ARGV.shift
+    end
+
+    def get
+        md5 = ARGV.shift
+        out = @client.getfile(md5)
+        print out
+    end
+
+    def backup
+        ARGV.each do |file|
+            unless FileTest.exists?(file)
+                $stderr.puts "%s: no such file" % file
+                next
+            end
+            unless FileTest.readable?(file)
+                $stderr.puts "%s: cannot read file" % file
+                next
+            end
+            md5 = @client.backup(file)
+            puts "%s: %s" % [file, md5]
+        end
+    end
+
+    def restore
+        file = ARGV.shift
+        md5 = ARGV.shift
+        @client.restore(file, md5)
+    end
+
+    def setup
+        Puppet::Log.newdestination(:console)
+
+        @client = nil
+        @server = nil
+
+        Puppet.settraps
+
+        if options[:debug]
+            Puppet::Log.level = :debug
+        elsif options[:verbose]
+            Puppet::Log.level = :info
+        end
+
+        # Now parse the config
+        Puppet.parse_config
+
+        if Puppet.settings.print_configs?
+                exit(Puppet.settings.print_configs ? 0 : 1)
+        end
+
+        begin
+            if options[:local] or options[:bucket]
+                path = options[:bucket] || Puppet[:bucketdir]
+                @client = Puppet::Network::Client.dipper.new(:Path => path)
+            else
+                require 'puppet/network/handler'
+                @client = Puppet::Network::Client.dipper.new(:Server => 
Puppet[:server])
+            end
+        rescue => detail
+            $stderr.puts detail
+            if Puppet[:trace]
+                puts detail.backtrace
+            end
+            exit(1)
+        end
+    end
+
+    def handle_version(arg)
+        puts "%s" % Puppet.version
+        exit
+    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 puppet-dev@googlegroups.com
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to