summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2011-02-08 12:18:31 -0800
committerJesse Wolfe <jes5199@gmail.com>2011-02-08 12:18:31 -0800
commit0971bda3d7b75a5292268b3a6acb1724fbb9852c (patch)
tree5ac3a9edb75cc9913afa691efea936400b1972dc
parente0613d808f52d08bc1a2fb4e075749f486d7768b (diff)
parent7b3b56ef7bfd32d7afb47fd71c2d9f606856d2e0 (diff)
downloadpuppet-0971bda3d7b75a5292268b3a6acb1724fbb9852c.tar.gz
puppet-0971bda3d7b75a5292268b3a6acb1724fbb9852c.tar.xz
puppet-0971bda3d7b75a5292268b3a6acb1724fbb9852c.zip
Merge remote branch 'dan/ticket/2.6.4/5977' into 2.6.next
-rw-r--r--lib/puppet/util/command_line.rb8
-rw-r--r--spec/unit/util/command_line_spec.rb24
2 files changed, 30 insertions, 2 deletions
diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb
index 3562a3dc0..4aff0a8cb 100644
--- a/lib/puppet/util/command_line.rb
+++ b/lib/puppet/util/command_line.rb
@@ -33,8 +33,12 @@ module Puppet
end
def available_subcommands
- absolute_appdir = $LOAD_PATH.collect { |x| File.join(x,'puppet','application') }.detect{ |x| File.directory?(x) }
- Dir[File.join(absolute_appdir, '*.rb')].map{|fn| File.basename(fn, '.rb')}
+ absolute_appdirs = $LOAD_PATH.collect do |x|
+ File.join(x,'puppet','application')
+ end.select{ |x| File.directory?(x) }
+ absolute_appdirs.inject([]) do |commands, dir|
+ commands + Dir[File.join(dir, '*.rb')].map{|fn| File.basename(fn, '.rb')}
+ end.uniq
end
def usage_message
diff --git a/spec/unit/util/command_line_spec.rb b/spec/unit/util/command_line_spec.rb
index 7ba965249..a648eb4a1 100644
--- a/spec/unit/util/command_line_spec.rb
+++ b/spec/unit/util/command_line_spec.rb
@@ -6,6 +6,7 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
require 'puppet/util/command_line'
describe Puppet::Util::CommandLine do
+ include PuppetSpec::Files
before do
@tty = stub("tty", :tty? => true )
@pipe = stub("pipe", :tty? => false)
@@ -105,4 +106,27 @@ describe Puppet::Util::CommandLine do
end
end
end
+ describe 'when loading commands' do
+ before do
+ @core_apps = ["describe", "filebucket", "kick", "queue", "resource", "agent", "cert", "apply", "doc", "master"]
+ @command_line = Puppet::Util::CommandLine.new("foo", %w{ client --help w hatever.pp }, @tty )
+ end
+ it 'should be able to find all existing commands' do
+ @core_apps.each do |command|
+ @command_line.available_subcommands.should include command
+ end
+ end
+ describe 'when multiple paths have applications' do
+ before do
+ @dir=tmpdir('command_line_plugin_test')
+ @appdir="#{@dir}/puppet/application"
+ FileUtils.mkdir_p(@appdir)
+ FileUtils.touch("#{@appdir}/foo.rb")
+ $LOAD_PATH.unshift(@dir)
+ end
+ it 'should be able to find commands from both paths' do
+ @command_line.available_subcommands.should == ['foo'] + @core_apps
+ end
+ end
+ end
end