gli 0.2.1 → 0.2.3
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.
- data/README.rdoc +1 -1
- data/lib/gli.rb +8 -7
- data/lib/gli/command.rb +4 -4
- data/lib/gli/options.rb +14 -0
- data/lib/support/scaffold.rb +5 -2
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -99,7 +99,7 @@ You can also specify some global code to run before, after and on errors:
|
|
99
99
|
puts "After successful execution of #{command.name}"
|
100
100
|
end
|
101
101
|
|
102
|
-
on_error do |
|
102
|
+
on_error do |ex|
|
103
103
|
puts "We go an error"
|
104
104
|
return true # does the standard error handling code
|
105
105
|
# return false # this would skip standard error handling code
|
data/lib/gli.rb
CHANGED
@@ -2,6 +2,7 @@ require 'gli/command_line_token.rb'
|
|
2
2
|
require 'gli/command.rb'
|
3
3
|
require 'gli/switch.rb'
|
4
4
|
require 'gli/flag.rb'
|
5
|
+
require 'gli/options.rb'
|
5
6
|
require 'support/help.rb'
|
6
7
|
require 'support/rdoc.rb'
|
7
8
|
|
@@ -40,22 +41,22 @@ module GLI
|
|
40
41
|
def default_value(val); @@next_default_value = val; end
|
41
42
|
|
42
43
|
# Create a flag, which is a switch that takes an argument
|
43
|
-
def flag(names)
|
44
|
-
flag = Flag.new(names,@@next_desc,@@next_arg_name,@@next_default_value,@@next_long_desc)
|
44
|
+
def flag(*names)
|
45
|
+
flag = Flag.new([names].flatten,@@next_desc,@@next_arg_name,@@next_default_value,@@next_long_desc)
|
45
46
|
flags[flag.name] = flag
|
46
47
|
clear_nexts
|
47
48
|
end
|
48
49
|
|
49
50
|
# Create a switch
|
50
|
-
def switch(names)
|
51
|
-
switch = Switch.new(names,@@next_desc,@@next_long_desc)
|
51
|
+
def switch(*names)
|
52
|
+
switch = Switch.new([names].flatten,@@next_desc,@@next_long_desc)
|
52
53
|
switches[switch.name] = switch
|
53
54
|
clear_nexts
|
54
55
|
end
|
55
56
|
|
56
57
|
# Define a command.
|
57
|
-
def command(names)
|
58
|
-
command = Command.new(names,@@next_desc,@@next_arg_name,@@next_long_desc)
|
58
|
+
def command(*names)
|
59
|
+
command = Command.new([names].flatten,@@next_desc,@@next_arg_name,@@next_long_desc)
|
59
60
|
commands[command.name] = command
|
60
61
|
yield command
|
61
62
|
clear_nexts
|
@@ -123,7 +124,7 @@ module GLI
|
|
123
124
|
# * command options (as a Hash)
|
124
125
|
# * arguments (as an Array)
|
125
126
|
def parse_options(args)
|
126
|
-
global_options,command,options,arguments = parse_options_helper(args.clone,
|
127
|
+
global_options,command,options,arguments = parse_options_helper(args.clone,Options.new,nil,Options.new,Array.new)
|
127
128
|
flags.each { |name,flag| global_options[name] = flag.default_value if !global_options[name] }
|
128
129
|
command.flags.each { |name,flag| options[name] = flag.default_value if !options[name] }
|
129
130
|
return [global_options,command,options,arguments]
|
data/lib/gli/command.rb
CHANGED
@@ -40,15 +40,15 @@ module GLI
|
|
40
40
|
# set the default value of the next flag
|
41
41
|
def default_value(val); @next_default_value = val; end
|
42
42
|
|
43
|
-
def flag(names)
|
44
|
-
flag = Flag.new(names,@next_desc,@next_arg_name,@next_default_value)
|
43
|
+
def flag(*names)
|
44
|
+
flag = Flag.new([names].flatten,@next_desc,@next_arg_name,@next_default_value)
|
45
45
|
flags[flag.name] = flag
|
46
46
|
clear_nexts
|
47
47
|
end
|
48
48
|
|
49
49
|
# Create a switch
|
50
|
-
def switch(names)
|
51
|
-
switch = Switch.new(names,@next_desc)
|
50
|
+
def switch(*names)
|
51
|
+
switch = Switch.new([names].flatten,@next_desc)
|
52
52
|
switches[switch.name] = switch
|
53
53
|
clear_nexts
|
54
54
|
end
|
data/lib/gli/options.rb
ADDED
data/lib/support/scaffold.rb
CHANGED
@@ -139,11 +139,13 @@ flag [:f,:flagname]
|
|
139
139
|
EOS
|
140
140
|
first = true
|
141
141
|
commands.each do |command|
|
142
|
-
|
143
|
-
file.puts <<EOS
|
142
|
+
file.puts <<EOS
|
144
143
|
|
145
144
|
desc 'Describe #{command} here'
|
146
145
|
arg_name 'Describe arguments to #{command} here'
|
146
|
+
EOS
|
147
|
+
if first
|
148
|
+
file.puts <<EOS
|
147
149
|
command :#{command} do |c|
|
148
150
|
c.desc 'Describe a switch to #{command}'
|
149
151
|
c.switch :s
|
@@ -171,6 +173,7 @@ EOS
|
|
171
173
|
first = false
|
172
174
|
end
|
173
175
|
file.puts <<EOS
|
176
|
+
|
174
177
|
pre do |global,command,options,args|
|
175
178
|
# Pre logic here
|
176
179
|
# Return true to proceed; false to abourt and not call the
|
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: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Copeland
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-25 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- lib/gli/command_line_token.rb
|
28
28
|
- lib/gli/flag.rb
|
29
29
|
- lib/gli/switch.rb
|
30
|
+
- lib/gli/options.rb
|
30
31
|
- lib/gli.rb
|
31
32
|
- lib/support/help.rb
|
32
33
|
- lib/support/rdoc.rb
|