diff --git a/features/todo.feature b/features/todo.feature index bea61f85..91f20bb1 100644 --- a/features/todo.feature +++ b/features/todo.feature @@ -41,6 +41,7 @@ Feature: The todo app has a nice user interface list - List things, such as tasks or contexts ls - LS things, such as tasks or contexts second - + third - """ Examples: | help | @@ -118,6 +119,7 @@ Feature: The todo app has a nice user interface create, new - Create a new task or context list - List things, such as tasks or contexts ls - LS things, such as tasks or contexts + third - first - second - chained - diff --git a/lib/gli/app.rb b/lib/gli/app.rb index 0c4edd8b..f777571f 100644 --- a/lib/gli/app.rb +++ b/lib/gli/app.rb @@ -20,15 +20,12 @@ module App # # path:: a path relative to somewhere in the LOAD_PATH, from which all .rb files will be required. def commands_from(path) - $LOAD_PATH.each do |load_path| - commands_path = File.join(load_path,path) - if File.exists? commands_path - Dir.entries(commands_path).sort.each do |entry| - file = File.join(commands_path,entry) - if file =~ /\.rb$/ - require file - end - end + if Pathname.new(path).absolute? and File.exists?(path) + load_commands(path) + else + $LOAD_PATH.each do |load_path| + commands_path = File.join(load_path,path) + load_commands(commands_path) end end end @@ -251,5 +248,18 @@ def program_name(override=nil) #:nodoc: def default_command(command) @default_command = command.to_sym end + + private + + def load_commands(path) + if File.exists? path + Dir.entries(path).sort.each do |entry| + file = File.join(path,entry) + if file =~ /\.rb$/ + require file + end + end + end + end end end diff --git a/test/apps/todo/bin/todo b/test/apps/todo/bin/todo index 1a550544..3d154d25 100755 --- a/test/apps/todo/bin/todo +++ b/test/apps/todo/bin/todo @@ -29,6 +29,7 @@ switch :otherswitch, :negatable => true version Todo::VERSION commands_from 'todo/commands' +commands_from File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'todo_plugins', 'commands')) command :first do |c| c.action { |g,o,a| puts "first: #{a.join(',')}" } end command :second do |c| c.action { |g,o,a| puts "second: #{a.join(',')}" } end diff --git a/test/apps/todo_plugins/commands/third.rb b/test/apps/todo_plugins/commands/third.rb new file mode 100644 index 00000000..ec937fb3 --- /dev/null +++ b/test/apps/todo_plugins/commands/third.rb @@ -0,0 +1 @@ +command :third do |c| c.action { |g,o,a| puts "third: #{a.join(',')}" } end