[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:00 UTC 2010


The following commit has been merged in the upstream branch:
commit 748aed9a4fe70cc2ecc0c782b694114356d9eb25
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Tue Apr 13 14:53:44 2010 -0700

    Fix #3552 single executable should display usage
    
    Added some tests to make the single executable command behavior
    explicit.
    Added logic to display the usage message if we're on a tty and no
    arguments are passed.
    
    Signed-off-by: Jesse Wolfe <jes5199 at gmail.com>

diff --git a/bin/puppet b/bin/puppet
index cffa891..2f497c5 100755
--- a/bin/puppet
+++ b/bin/puppet
@@ -7,13 +7,10 @@ builtins = Dir[File.join(absolute_appdir, '*.rb')].map{|fn| File.basename(fn, '.
 usage = "Usage: puppet command <space separated arguments>"
 available = "Available commands are: #{builtins.sort.join(', ')}"
 
-command_name = ARGV.empty? || ARGV.first[/^-/] || ARGV.first =~ /\.pp/ || ARGV.first =~ /\.rb/ ? nil : ARGV.shift # subcommand?
+require 'puppet/util/command_line'
+command_line = Puppet::Util::CommandLine.shift_subcommand_from_argv
 
-if command_name.nil? # It's old-style puppet, executing something
-    command_name = "main"
-end
-
-if command_name.nil? # main
+if command_name.nil?
     puts usage, available
 elsif builtins.include?(command_name) #subcommand
     require File.join(appdir, command_name)
diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb
new file mode 100644
index 0000000..5945436
--- /dev/null
+++ b/lib/puppet/util/command_line.rb
@@ -0,0 +1,15 @@
+module Puppet
+    module Util
+        module CommandLine
+            def self.shift_subcommand_from_argv( argv = ARGV, stdin = STDIN )
+                if ! argv.first
+                    "main" unless stdin.tty? # ttys get usage info
+                elsif argv.first =~ /^-|\.pp$|\.rb$/
+                    "main"
+                else
+                    argv.shift
+                end
+            end
+        end
+    end
+end
diff --git a/spec/unit/util/command_line.rb b/spec/unit/util/command_line.rb
new file mode 100644
index 0000000..d6bbcd1
--- /dev/null
+++ b/spec/unit/util/command_line.rb
@@ -0,0 +1,70 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+
+require 'puppet/util/command_line'
+
+describe Puppet::Util::CommandLine do
+    before do
+        @tty  = stub("tty",  :tty? => true )
+        @pipe = stub("pipe", :tty? => false)
+    end
+
+    it "should pull off the first argument if it looks like a subcommand" do
+        args    = %w( client --help whatever.pp )
+        command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty )
+
+        command.should == "client"
+        args.should    == %w( --help whatever.pp )
+    end
+
+    it "should use main if the first argument looks like a .pp file" do
+        args    = %w( whatever.pp )
+        command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty )
+
+        command.should == "main"
+        args.should    == %w( whatever.pp )
+    end
+
+    it "should use main if the first argument looks like a .rb file" do
+        args    = %w( whatever.rb )
+        command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty )
+
+        command.should == "main"
+        args.should    == %w( whatever.rb )
+    end
+
+    it "should use main if the first argument looks like a flag" do
+        args    = %w( --debug )
+        command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty )
+
+        command.should == "main"
+        args.should    == %w( --debug )
+    end
+
+    it "should use main if the first argument is -" do
+        args    = %w( - )
+        command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty )
+
+        command.should == "main"
+        args.should    == %w( - )
+    end
+
+    it "should return nil if there are no arguments on a tty" do
+        args    = []
+        command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @tty )
+
+        command.should == nil
+        args.should    == []
+    end
+
+    it "should use main if there are no arguments on a pipe" do
+        args    = []
+        command = Puppet::Util::CommandLine.shift_subcommand_from_argv( args, @pipe )
+
+        command.should == "main"
+        args.should    == []
+    end
+
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list