I'd be far happier with Puppet::Util::ComandLine owning $puppet_subcommand_name. Something like:

module Puppet::Util:CommandLine
  def self.subcommand_name
    @subcommand_name ||= @shift_subcommand_from_argv
  end
end

Then the defaults just relies on that:

name = legacy_name[ Puppet::Util::CommandLine.subcommand_name] || $0.gsub(/.+#{File::SEPARATOR}/,'').sub(/\.rb$/, '')

Still effectively a global, but much more obvious, and it has the benefit of doing the right thing other ways. And if you made a writer 'subcommand_name' people could easily override it, which is often enough needed.

On Apr 21, 2010, at 11:54 AM, Jesse Wolfe wrote:

Puppet's defaults change depending on which command invokes them.
This patch makes sure that we use the maintain the current behavior.
This is a temporary fix until I implement feature #2935.

Signed-off-by: Jesse Wolfe <[email protected]>
---
bin/puppet             |   12 ++++++------
lib/puppet/defaults.rb |   15 ++++++++++++++-
2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/bin/puppet b/bin/puppet
index 2f497c5..bf4ee3a 100755
--- a/bin/puppet
+++ b/bin/puppet
@@ -8,13 +8,13 @@ usage = "Usage: puppet command <space separated arguments>"
available = "Available commands are: #{builtins.sort.join(', ')}"

require 'puppet/util/command_line'
-command_line = Puppet::Util::CommandLine.shift_subcommand_from_argv
+$puppet_subcommand_name = Puppet::Util::CommandLine.shift_subcommand_from_argv

-if command_name.nil?
+if $puppet_subcommand_name.nil?
    puts usage, available
-elsif builtins.include?(command_name) #subcommand
-    require File.join(appdir, command_name)
-    Puppet::Application[command_name].run
+elsif builtins.include?($puppet_subcommand_name) #subcommand
+    require File.join(appdir, $puppet_subcommand_name)
+    Puppet::Application[$puppet_subcommand_name].run
else
- abort "Error: Unknown command #{command_name}.\n#{usage} \n#{available}" + abort "Error: Unknown command #{$puppet_subcommand_name}. \n#{usage}\n#{available}"
end
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 2f397f4..b4f89cf 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -4,7 +4,20 @@ module Puppet
    # use basedirs that are in the user's home directory.
    conf = nil
    var = nil
-    name = $0.gsub(/.+#{File::SEPARATOR}/,'').sub(/\.rb$/, '')
+
+    legacy_name = Hash.new{ |h,k| k }.update({
+        'agent'      => 'puppetd',
+        'cert'       => 'puppetca',
+        'doc'        => 'puppetdoc',
+        'filebucket' => 'filebucket',
+        'apply'      => 'puppet',
+        'describe'   => 'pi',
+        'queue'      => 'puppetqd',
+        'resource'   => 'ralsh',
+        'kick'       => 'puppetrun',
+        'master'     => 'puppetmasterd',
+    })
+ name = legacy_name[ $puppet_subcommand_name ] || $0.gsub(/. +#{File::SEPARATOR}/,'').sub(/\.rb$/, '')

    # Make File.expand_path happy
    require 'etc'
--
1.6.3.3

--
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 .



--
A classic is something that everybody wants to have read and nobody
wants to read. -- Mark Twain
---------------------------------------------------------------------
Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199

--
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