diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2010-04-30 14:54:07 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 63e2e56d3172bdc80aaca5f5ddde5811728e3c76 (patch) | |
| tree | 38e3607fe83223d135f1c327682dbd8698bb138d /lib/puppet/util/command_line.rb | |
| parent | b6e2ce6a85c953fcd57a3b837ccaa794a634dc22 (diff) | |
| download | puppet-63e2e56d3172bdc80aaca5f5ddde5811728e3c76.tar.gz puppet-63e2e56d3172bdc80aaca5f5ddde5811728e3c76.tar.xz puppet-63e2e56d3172bdc80aaca5f5ddde5811728e3c76.zip | |
feature #2276 Single Executable: subcommand method
Extract the logic to determine the subcommand name into a method.
Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
Diffstat (limited to 'lib/puppet/util/command_line.rb')
| -rw-r--r-- | lib/puppet/util/command_line.rb | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb index f231ee7f8..5fe07b28d 100644 --- a/lib/puppet/util/command_line.rb +++ b/lib/puppet/util/command_line.rb @@ -1,12 +1,45 @@ module Puppet module Util module CommandLine - def self.shift_subcommand_from_argv( argv = ARGV, stdin = STDIN ) - case argv.first - when nil; "apply" unless stdin.tty? # ttys get usage info - when "--help"; nil # help should give you usage, not the help for `puppet apply` - when /^-|\.pp$|\.rb$/; "apply" - else argv.shift + def self.subcommand_name(*args) + subcommand_name, args = subcommand_and_args(*args) + return subcommand_name + end + + def self.args(*args) + subcommand_name, args = subcommand_and_args(*args) + return args + end + + LegacyName = 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', + }) + + def self.legacy_executable_name(*args) + LegacyName[ subcommand_name(*args) ] + end + + def self.subcommand_and_args( zero = $0, argv = ARGV, stdin = STDIN ) + zero = zero.gsub(/.*#{File::SEPARATOR}/,'').sub(/\.rb$/, '') + + if zero == 'puppet' + case argv.first + when nil; [ stdin.tty? ? nil : "apply", argv] # ttys get usage info + when "--help"; [nil, argv] # help should give you usage, not the help for `puppet apply` + when /^-|\.pp$|\.rb$/; ["apply", argv] + else [ argv.first, argv[1..-1] ] + end + else + [ zero, argv ] end end end |
