gli 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,6 +41,7 @@ Feature: The todo app has a nice user interface
41
41
  list - List things, such as tasks or contexts
42
42
  ls - LS things, such as tasks or contexts
43
43
  second -
44
+ third -
44
45
  """
45
46
  Examples:
46
47
  | help |
@@ -118,6 +119,7 @@ Feature: The todo app has a nice user interface
118
119
  create, new - Create a new task or context
119
120
  list - List things, such as tasks or contexts
120
121
  ls - LS things, such as tasks or contexts
122
+ third -
121
123
  first -
122
124
  second -
123
125
  chained -
data/lib/gli/app.rb CHANGED
@@ -12,23 +12,31 @@ module GLI
12
12
  include DSL
13
13
  include AppSupport
14
14
 
15
- # Loads ruby files in the load path that start with
15
+ # Loads ruby files in the load path that start with
16
16
  # +path+, which are presumed to be commands for your executable.
17
- # This is a glorified +require+, but could also be used as a plugin mechanism.
18
- # You could manipualte the load path at runtime and this call
19
- # would find those files
17
+ # This is useful for decomposing your bin file into different classes, but
18
+ # can also be used as a plugin mechanism, allowing users to provide additional
19
+ # commands for your app at runtime. All that being said, it's basically
20
+ # a glorified +require+.
20
21
  #
21
- # path:: a path relative to somewhere in the <code>LOAD_PATH</code>, from which all <code>.rb</code> files will be required.
22
+ # path:: a path from which to load <code>.rb</code> files that, presumably, contain commands. If this is an absolute path,
23
+ # any files in that path are loaded. If not, it is interpretted as relative to somewhere
24
+ # in the <code>LOAD_PATH</code>.
25
+ #
26
+ # == Example:
27
+ #
28
+ # # loads *.rb from your app's install - great for decomposing your bin file
29
+ # commands_from "my_app/commands"
30
+ #
31
+ # # loads *.rb files from the user's home dir - great and an extension/plugin mechanism
32
+ # commands_from File.join(ENV["HOME"],".my_app","plugins")
22
33
  def commands_from(path)
23
- $LOAD_PATH.each do |load_path|
24
- commands_path = File.join(load_path,path)
25
- if File.exists? commands_path
26
- Dir.entries(commands_path).sort.each do |entry|
27
- file = File.join(commands_path,entry)
28
- if file =~ /\.rb$/
29
- require file
30
- end
31
- end
34
+ if Pathname.new(path).absolute? and File.exists?(path)
35
+ load_commands(path)
36
+ else
37
+ $LOAD_PATH.each do |load_path|
38
+ commands_path = File.join(load_path,path)
39
+ load_commands(commands_path)
32
40
  end
33
41
  end
34
42
  end
@@ -37,7 +45,7 @@ module GLI
37
45
  # of what your program does that will appear in the help output.
38
46
  #
39
47
  # +description+:: A String of the short description of your program's purpose
40
- def program_desc(description=nil)
48
+ def program_desc(description=nil)
41
49
  if description
42
50
  @program_desc = description
43
51
  end
@@ -251,5 +259,18 @@ module GLI
251
259
  def default_command(command)
252
260
  @default_command = command.to_sym
253
261
  end
262
+
263
+ private
264
+
265
+ def load_commands(path)
266
+ if File.exists? path
267
+ Dir.entries(path).sort.each do |entry|
268
+ file = File.join(path,entry)
269
+ if file =~ /\.rb$/
270
+ require file
271
+ end
272
+ end
273
+ end
274
+ end
254
275
  end
255
276
  end
data/lib/gli/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module GLI
2
2
  unless const_defined? :VERSION
3
- VERSION = '2.3.0' #:nodoc:
3
+ VERSION = '2.4.0' #:nodoc:
4
4
  end
5
5
  end
@@ -29,6 +29,7 @@ switch :otherswitch, :negatable => true
29
29
  version Todo::VERSION
30
30
 
31
31
  commands_from 'todo/commands'
32
+ commands_from File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'todo_plugins', 'commands'))
32
33
 
33
34
  command :first do |c| c.action { |g,o,a| puts "first: #{a.join(',')}" } end
34
35
  command :second do |c| c.action { |g,o,a| puts "second: #{a.join(',')}" } end
@@ -0,0 +1 @@
1
+ command :third do |c| c.action { |g,o,a| puts "third: #{a.join(',')}" } end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-02 00:00:00.000000000 Z
12
+ date: 2012-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -311,6 +311,8 @@ files:
311
311
  dGVzdC9hcHBzL3RvZG8vdG9kby5nZW1zcGVj
312
312
  - !binary |-
313
313
  dGVzdC9hcHBzL3RvZG8vdG9kby5yZG9j
314
+ - !binary |-
315
+ dGVzdC9hcHBzL3RvZG9fcGx1Z2lucy9jb21tYW5kcy90aGlyZC5yYg==
314
316
  - !binary |-
315
317
  dGVzdC9jb25maWcueWFtbA==
316
318
  - !binary |-
@@ -365,7 +367,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
365
367
  version: '0'
366
368
  segments:
367
369
  - 0
368
- hash: 3822562624553397534
370
+ hash: -3686138508377363663
369
371
  required_rubygems_version: !ruby/object:Gem::Requirement
370
372
  none: false
371
373
  requirements:
@@ -374,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
374
376
  version: '0'
375
377
  segments:
376
378
  - 0
377
- hash: 3822562624553397534
379
+ hash: -3686138508377363663
378
380
  requirements: []
379
381
  rubyforge_project: gli
380
382
  rubygems_version: 1.8.24
@@ -421,6 +423,8 @@ test_files:
421
423
  dGVzdC9hcHBzL3RvZG8vdG9kby5nZW1zcGVj
422
424
  - !binary |-
423
425
  dGVzdC9hcHBzL3RvZG8vdG9kby5yZG9j
426
+ - !binary |-
427
+ dGVzdC9hcHBzL3RvZG9fcGx1Z2lucy9jb21tYW5kcy90aGlyZC5yYg==
424
428
  - !binary |-
425
429
  dGVzdC9jb25maWcueWFtbA==
426
430
  - !binary |-