gli 1.2.6 → 1.3.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.
- data/README.rdoc +4 -1
- data/bin/gli +3 -1
- data/gli.rdoc +1 -0
- data/lib/gli.rb +85 -60
- data/lib/gli/command.rb +17 -1
- data/lib/gli/command_line_token.rb +4 -4
- data/lib/gli/copy_options_to_aliases.rb +33 -0
- data/lib/gli/flag.rb +2 -1
- data/lib/gli/switch.rb +12 -5
- data/lib/gli/terminal.rb +2 -2
- data/lib/gli_version.rb +1 -1
- data/lib/support/help.rb +22 -0
- data/lib/support/rdoc.rb +4 -0
- data/lib/support/scaffold.rb +6 -1
- metadata +73 -25
data/README.rdoc
CHANGED
@@ -34,8 +34,11 @@ Known to work on
|
|
34
34
|
|
35
35
|
* 1.8.7
|
36
36
|
* 1.9.2
|
37
|
+
* Ruby Enterprise Edition 1.8.7
|
38
|
+
* Rubinius 1.0.1
|
39
|
+
* JRuby 1.5.2
|
37
40
|
|
38
|
-
|
41
|
+
If you're interested in other versions of Ruby, let me know, and I'll add them to my test suite
|
39
42
|
|
40
43
|
== Documentation
|
41
44
|
|
data/bin/gli
CHANGED
@@ -19,6 +19,8 @@ require 'gli_version'
|
|
19
19
|
|
20
20
|
include GLI
|
21
21
|
|
22
|
+
program_desc 'gli allows you to create the scaffolding for a GLI-powered application'
|
23
|
+
|
22
24
|
version GLI::VERSION
|
23
25
|
desc 'Be verbose'
|
24
26
|
switch :v
|
@@ -67,4 +69,4 @@ post do |global,command,options,args|
|
|
67
69
|
puts "Executed #{command.name}" if global[:v]
|
68
70
|
end
|
69
71
|
|
70
|
-
run(ARGV)
|
72
|
+
exit run(ARGV)
|
data/gli.rdoc
CHANGED
data/lib/gli.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require 'gli/command_line_token.rb'
|
2
1
|
require 'gli/command.rb'
|
3
|
-
require 'gli/
|
2
|
+
require 'gli/command_line_token.rb'
|
3
|
+
require 'gli/copy_options_to_aliases.rb'
|
4
|
+
require 'gli/exceptions.rb'
|
4
5
|
require 'gli/flag.rb'
|
5
6
|
require 'gli/options.rb'
|
6
|
-
require 'gli/
|
7
|
+
require 'gli/switch.rb'
|
7
8
|
require 'gli_version.rb'
|
8
9
|
require 'support/help.rb'
|
9
10
|
require 'support/rdoc.rb'
|
@@ -15,6 +16,7 @@ require 'etc'
|
|
15
16
|
# specific options, and then command arguments.
|
16
17
|
module GLI
|
17
18
|
extend self
|
19
|
+
include CopyOptionsToAliases
|
18
20
|
|
19
21
|
@@program_name = $0.split(/\//)[-1]
|
20
22
|
@@post_block = nil
|
@@ -24,6 +26,9 @@ module GLI
|
|
24
26
|
@@use_openstruct = false
|
25
27
|
@@version = nil
|
26
28
|
@@stderr = $stderr
|
29
|
+
@@program_desc = nil
|
30
|
+
@@skips_pre = false
|
31
|
+
@@skips_post = false
|
27
32
|
|
28
33
|
# Override the device of stderr; exposed only for testing
|
29
34
|
def error_device=(e) #:nodoc:
|
@@ -38,6 +43,7 @@ module GLI
|
|
38
43
|
@@version = nil
|
39
44
|
@@config_file = nil
|
40
45
|
@@use_openstruct = false
|
46
|
+
@@prog_desc = nil
|
41
47
|
clear_nexts
|
42
48
|
end
|
43
49
|
|
@@ -47,6 +53,31 @@ module GLI
|
|
47
53
|
# +description+:: A String of the short descripiton of the switch, flag, or command following
|
48
54
|
def desc(description); @@next_desc = description; end
|
49
55
|
|
56
|
+
# Describe the overall application/programm. This should be a one-sentence summary
|
57
|
+
# of what your program does that will appear in the help output.
|
58
|
+
#
|
59
|
+
# +description+:: A String of the short description of your program's purpose
|
60
|
+
def program_desc(description=nil)
|
61
|
+
if description
|
62
|
+
@@program_desc = description
|
63
|
+
end
|
64
|
+
@@program_desc
|
65
|
+
end
|
66
|
+
|
67
|
+
# Use this if the following command should not have the pre block executed.
|
68
|
+
# By default, the pre block is executed before each command and can result in
|
69
|
+
# aborting the call. Using this will avoid that behavior for the following command
|
70
|
+
def skips_pre
|
71
|
+
@@skips_pre = true
|
72
|
+
end
|
73
|
+
|
74
|
+
# Use this if the following command should not have the post block executed.
|
75
|
+
# By default, the post block is executed after each command.
|
76
|
+
# Using this will avoid that behavior for the following command
|
77
|
+
def skips_post
|
78
|
+
@@skips_post = true
|
79
|
+
end
|
80
|
+
|
50
81
|
# Provide a longer, more detailed description. This
|
51
82
|
# will be reformatted and wrapped to fit in the terminal's columns
|
52
83
|
#
|
@@ -127,7 +158,7 @@ module GLI
|
|
127
158
|
# +names+:: a String or Symbol, or an Array of String or Symbol that represent all the different names and aliases for this command.
|
128
159
|
#
|
129
160
|
def command(*names)
|
130
|
-
command = Command.new([names].flatten,@@next_desc,@@next_arg_name,@@next_long_desc)
|
161
|
+
command = Command.new([names].flatten,@@next_desc,@@next_arg_name,@@next_long_desc,@@skips_pre,@@skips_post)
|
131
162
|
commands[command.name] = command
|
132
163
|
yield command
|
133
164
|
clear_nexts
|
@@ -193,26 +224,28 @@ module GLI
|
|
193
224
|
exit_code = 0
|
194
225
|
begin
|
195
226
|
config = parse_config
|
196
|
-
|
227
|
+
override_defaults_based_on_config(config)
|
228
|
+
global_options,command,options,arguments = parse_options(args)
|
197
229
|
copy_options_to_aliased_versions(global_options,command,options)
|
198
230
|
global_options = convert_to_openstruct?(global_options)
|
199
231
|
options = convert_to_openstruct?(options)
|
200
232
|
if proceed?(global_options,command,options,arguments)
|
201
233
|
command = commands[:help] if !command
|
202
234
|
command.execute(global_options,options,arguments)
|
203
|
-
|
235
|
+
if !command.skips_post && @@post_block
|
236
|
+
@@post_block.call(global_options,command,options,arguments)
|
237
|
+
end
|
204
238
|
end
|
205
239
|
rescue Exception => ex
|
206
240
|
|
207
241
|
@@stderr.puts error_message(ex) if regular_error_handling?(ex)
|
208
242
|
|
209
|
-
raise ex if ENV['GLI_DEBUG'] == 'true'
|
210
|
-
|
211
243
|
exit_code = if ex.respond_to? :exit_code
|
212
244
|
ex.exit_code
|
213
245
|
else
|
214
246
|
-2
|
215
247
|
end
|
248
|
+
raise ex if ENV['GLI_DEBUG'] == 'true'
|
216
249
|
end
|
217
250
|
exit_code
|
218
251
|
end
|
@@ -220,7 +253,9 @@ module GLI
|
|
220
253
|
# True if we should proceed with executing the command; this calls
|
221
254
|
# the pre block if it's defined
|
222
255
|
def proceed?(global_options,command,options,arguments) #:nodoc:
|
223
|
-
if
|
256
|
+
if command && command.skips_pre
|
257
|
+
true
|
258
|
+
elsif @@pre_block
|
224
259
|
@@pre_block.call(global_options,command,options,arguments)
|
225
260
|
else
|
226
261
|
true
|
@@ -288,36 +323,15 @@ module GLI
|
|
288
323
|
# For example, if a flag works with either -f or --flag, this will copy the value from [:f] to [:flag]
|
289
324
|
# to allow the user to access the options by any alias
|
290
325
|
def copy_options_to_aliased_versions(global_options,command,options) # :nodoc:
|
291
|
-
copy_options_to_aliases(global_options
|
292
|
-
copy_options_to_aliases(options
|
293
|
-
end
|
294
|
-
|
295
|
-
# For each option in options, copies its value to keys for the aliases of the flags or
|
296
|
-
# switches in gli_like
|
297
|
-
#
|
298
|
-
# options - Hash of options parsed from command line; this is an I/O param
|
299
|
-
# gli_like - Object resonding to flags and switches in the same way that GLI or a Command instance do
|
300
|
-
def copy_options_to_aliases(options,gli_like) # :nodoc:
|
301
|
-
new_options = {}
|
302
|
-
options.each do |key,value|
|
303
|
-
if gli_like.flags[key] && gli_like.flags[key].aliases
|
304
|
-
gli_like.flags[key].aliases.each do |alias_name|
|
305
|
-
new_options[alias_name] = value
|
306
|
-
end
|
307
|
-
elsif gli_like.switches[key] && gli_like.switches[key].aliases
|
308
|
-
gli_like.switches[key].aliases.each do |alias_name|
|
309
|
-
new_options[alias_name] = value
|
310
|
-
end
|
311
|
-
end
|
312
|
-
end
|
313
|
-
options.merge!(new_options)
|
326
|
+
copy_options_to_aliases(global_options)
|
327
|
+
command.copy_options_to_aliases(options)
|
314
328
|
end
|
315
329
|
|
316
330
|
def parse_config # :nodoc:
|
317
331
|
return nil if @@config_file.nil?
|
318
332
|
require 'yaml'
|
319
333
|
if File.exist?(@@config_file)
|
320
|
-
File.open(@@config_file) { |
|
334
|
+
File.open(@@config_file) { |file| YAML::load(file) }
|
321
335
|
else
|
322
336
|
{}
|
323
337
|
end
|
@@ -328,14 +342,8 @@ module GLI
|
|
328
342
|
# * Command
|
329
343
|
# * command options (as a Hash)
|
330
344
|
# * arguments (as an Array)
|
331
|
-
def parse_options(args
|
332
|
-
|
333
|
-
if config.nil?
|
334
|
-
config = {}
|
335
|
-
else
|
336
|
-
command_configs = config.delete(GLI::InitConfig::COMMANDS_KEY) if !config.nil?
|
337
|
-
end
|
338
|
-
global_options,command,options,arguments = parse_options_helper(args.clone,config,nil,Hash.new,Array.new,command_configs)
|
345
|
+
def parse_options(args) # :nodoc:
|
346
|
+
global_options,command,options,arguments = parse_options_helper(args.clone,Hash.new,nil,Hash.new,Array.new)
|
339
347
|
flags.each { |name,flag| global_options[name] = flag.default_value if !global_options[name] }
|
340
348
|
command.flags.each { |name,flag| options[name] = flag.default_value if !options[name] }
|
341
349
|
return [global_options,command,options,arguments]
|
@@ -344,11 +352,11 @@ module GLI
|
|
344
352
|
# Finds the index of the first non-flag
|
345
353
|
# argument or -1 if there wasn't one.
|
346
354
|
def find_non_flag_index(args) # :nodoc:
|
347
|
-
args.
|
348
|
-
return
|
349
|
-
return
|
355
|
+
args.each_with_index do |item,index|
|
356
|
+
return index if item =~ /^[^\-]/
|
357
|
+
return index-1 if item =~ /^\-\-$/
|
350
358
|
end
|
351
|
-
-1
|
359
|
+
-1
|
352
360
|
end
|
353
361
|
|
354
362
|
def clear_nexts # :nodoc:
|
@@ -356,6 +364,8 @@ module GLI
|
|
356
364
|
@@next_arg_name = nil
|
357
365
|
@@next_default_value = nil
|
358
366
|
@@next_long_desc = nil
|
367
|
+
@@skips_pre = false
|
368
|
+
@@skips_post = false
|
359
369
|
end
|
360
370
|
|
361
371
|
clear_nexts
|
@@ -376,7 +386,6 @@ module GLI
|
|
376
386
|
# <code>command</code>:: the Command that has been identified (or nil if not identified yet)
|
377
387
|
# <code>command_options</code>:: options for Command
|
378
388
|
# <code>arguments</code>:: the arguments for Command
|
379
|
-
# <code>command_configs</code>:: the configuration file for all commands, used as defaults
|
380
389
|
#
|
381
390
|
# This works by finding the first non-switch/flag argument, and taking that sublist and trying to pick out
|
382
391
|
# flags and switches. After this is done, one of the following is true:
|
@@ -389,7 +398,7 @@ module GLI
|
|
389
398
|
#
|
390
399
|
# Once the command has been found, we start looking for command-specific flags and switches.
|
391
400
|
# When those have been found, we know the rest of the argument list is arguments for the command
|
392
|
-
def parse_options_helper(args,global_options,command,command_options,arguments
|
401
|
+
def parse_options_helper(args,global_options,command,command_options,arguments) # :nodoc:
|
393
402
|
non_flag_i = find_non_flag_index(args)
|
394
403
|
all_flags = false
|
395
404
|
if non_flag_i == 0
|
@@ -401,9 +410,8 @@ module GLI
|
|
401
410
|
return parse_options_helper(args,
|
402
411
|
global_options,
|
403
412
|
command,
|
404
|
-
|
405
|
-
arguments
|
406
|
-
command_configs)
|
413
|
+
Hash.new,
|
414
|
+
arguments)
|
407
415
|
else
|
408
416
|
return global_options,command,command_options,arguments + args
|
409
417
|
end
|
@@ -453,7 +461,7 @@ module GLI
|
|
453
461
|
return [global_options,command,command_options,arguments] if rest.empty?
|
454
462
|
# If we have no more options we've parsed them all
|
455
463
|
# and rest may have more
|
456
|
-
return parse_options_helper(rest,global_options,command,command_options,arguments
|
464
|
+
return parse_options_helper(rest,global_options,command,command_options,arguments)
|
457
465
|
else
|
458
466
|
if command
|
459
467
|
check = rest
|
@@ -477,23 +485,17 @@ module GLI
|
|
477
485
|
return parse_options_helper(rest,
|
478
486
|
global_options,
|
479
487
|
command,
|
480
|
-
|
481
|
-
arguments
|
482
|
-
command_configs)
|
488
|
+
Hash.new,
|
489
|
+
arguments)
|
483
490
|
end
|
484
491
|
end
|
485
492
|
|
486
493
|
end
|
487
494
|
|
488
|
-
def default_command_options(command,command_configs) # :nodoc:
|
489
|
-
options = (command_configs && command_configs[command.name.to_sym]) || {}
|
490
|
-
end
|
491
|
-
|
492
495
|
def find_command(name) # :nodoc:
|
493
496
|
sym = name.to_sym
|
494
497
|
return commands[name.to_sym] if commands[sym]
|
495
|
-
commands.
|
496
|
-
command = commands[command_name]
|
498
|
+
commands.each do |command_name,command|
|
497
499
|
return command if (command.aliases && command.aliases.include?(sym))
|
498
500
|
end
|
499
501
|
nil
|
@@ -517,4 +519,27 @@ module GLI
|
|
517
519
|
end
|
518
520
|
end
|
519
521
|
end
|
522
|
+
|
523
|
+
# Sets the default values for flags based on the configuration
|
524
|
+
def override_defaults_based_on_config(config)
|
525
|
+
config ||= {}
|
526
|
+
config['commands'] ||= {}
|
527
|
+
|
528
|
+
override_default(flags,config)
|
529
|
+
override_default(switches,config)
|
530
|
+
|
531
|
+
commands.each do |command_name,command|
|
532
|
+
command_config = config['commands'][command_name] || {}
|
533
|
+
|
534
|
+
override_default(command.flags,command_config)
|
535
|
+
override_default(command.switches,command_config)
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
def override_default(tokens,config)
|
540
|
+
tokens.each do |name,token|
|
541
|
+
token.default_value=config[name] if config[name]
|
542
|
+
end
|
543
|
+
end
|
544
|
+
|
520
545
|
end
|
data/lib/gli/command.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'gli/command_line_token.rb'
|
2
|
+
require 'gli/copy_options_to_aliases.rb'
|
2
3
|
|
3
4
|
module GLI
|
4
5
|
# A command to be run, in context of global flags and switches. You are given an instance of this class
|
@@ -6,6 +7,7 @@ module GLI
|
|
6
7
|
# command-specific command-line arguments, much as you use the methods in GLI to describe the global
|
7
8
|
# command-line interface
|
8
9
|
class Command < CommandLineToken
|
10
|
+
include CopyOptionsToAliases
|
9
11
|
|
10
12
|
# Create a new command
|
11
13
|
#
|
@@ -13,9 +15,13 @@ module GLI
|
|
13
15
|
# +description+:: short description of this command as a Strign
|
14
16
|
# +arguments_name+:: description of the arguments as a String, or nil if this command doesn't take arguments
|
15
17
|
# +long_desc+:: a longer description of the command, possibly with multiple lines and text formatting
|
16
|
-
|
18
|
+
# +skips_pre+:: if true, this command advertises that it doesn't want the pre block called first
|
19
|
+
# +skips_post+:: if true, this command advertises that it doesn't want the post block called after it
|
20
|
+
def initialize(names,description,arguments_name=nil,long_desc=nil,skips_pre=false,skips_post=false) # :nodoc:
|
17
21
|
super(names,description,long_desc)
|
18
22
|
@arguments_description = arguments_name || ''
|
23
|
+
@skips_pre = skips_pre
|
24
|
+
@skips_post = skips_post
|
19
25
|
clear_nexts
|
20
26
|
end
|
21
27
|
|
@@ -24,6 +30,16 @@ module GLI
|
|
24
30
|
@arguments_description
|
25
31
|
end
|
26
32
|
|
33
|
+
# If true, this command doesn't want the pre block run before it executes
|
34
|
+
def skips_pre #:nodoc:
|
35
|
+
@skips_pre
|
36
|
+
end
|
37
|
+
|
38
|
+
# If true, this command doesn't want the post block run before it executes
|
39
|
+
def skips_post #:nodoc:
|
40
|
+
@skips_post
|
41
|
+
end
|
42
|
+
|
27
43
|
# Return the Array of the command's names
|
28
44
|
def names #:nodoc:
|
29
45
|
all_forms
|
@@ -38,9 +38,9 @@ module GLI
|
|
38
38
|
# Allow strings; convert to symbols
|
39
39
|
names = [names].flatten.map { |name| name.to_sym }
|
40
40
|
names_hash = Hash.new
|
41
|
-
names.each do |
|
42
|
-
raise ArgumentError.new("#{
|
43
|
-
names_hash[self.class.name_as_string(
|
41
|
+
names.each do |name|
|
42
|
+
raise ArgumentError.new("#{name} has spaces; they are not allowed") if name.to_s =~ /\s/
|
43
|
+
names_hash[self.class.name_as_string(name)] = true
|
44
44
|
end
|
45
45
|
name = names.shift
|
46
46
|
aliases = names.length > 0 ? names : nil
|
@@ -50,7 +50,7 @@ module GLI
|
|
50
50
|
def all_forms_a
|
51
51
|
forms = [self.class.name_as_string(name)]
|
52
52
|
if aliases
|
53
|
-
forms |= aliases.collect { |
|
53
|
+
forms |= aliases.collect { |one_alias| self.class.name_as_string(one_alias) }.sort { |one,two| two.length <=> one.length }
|
54
54
|
end
|
55
55
|
forms
|
56
56
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module GLI
|
2
|
+
|
3
|
+
# Mixin that both GLI and Command can use to copy command-line options to the aliased versions
|
4
|
+
# of flags and switches
|
5
|
+
#
|
6
|
+
# includers must provide the methods +flags+ and +switches+ that return an Array of Flag or Switch,
|
7
|
+
# respectively
|
8
|
+
module CopyOptionsToAliases # :nodoc:
|
9
|
+
# For each option in options, copies its value to keys for the aliases of the flags or
|
10
|
+
# switches in gli_like
|
11
|
+
#
|
12
|
+
# options - Hash of options parsed from command line; this is an I/O param
|
13
|
+
def copy_options_to_aliases(options) # :nodoc:
|
14
|
+
new_options = {}
|
15
|
+
options.each do |key,value|
|
16
|
+
if flags[key] && flags[key].aliases
|
17
|
+
copy_aliases(flags[key].aliases,new_options,value)
|
18
|
+
elsif switches[key] && switches[key].aliases
|
19
|
+
copy_aliases(switches[key].aliases,new_options,value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
options.merge!(new_options)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def copy_aliases(aliases,new_options,value)
|
28
|
+
aliases.each do |alias_name|
|
29
|
+
new_options[alias_name] = value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/gli/flag.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'gli/command_line_token.rb'
|
2
|
+
require 'gli/switch.rb'
|
2
3
|
|
3
4
|
module GLI
|
4
5
|
# Defines a flag, which is to say a switch that takes an argument
|
5
6
|
class Flag < Switch # :nodoc:
|
6
7
|
|
7
|
-
|
8
|
+
attr_accessor :default_value
|
8
9
|
|
9
10
|
def initialize(names,description,argument_name=nil,default=nil,long_desc=nil)
|
10
11
|
super(names,description,long_desc)
|
data/lib/gli/switch.rb
CHANGED
@@ -6,24 +6,31 @@ module GLI
|
|
6
6
|
|
7
7
|
def initialize(names,description,long_desc=nil)
|
8
8
|
super(names,description,long_desc)
|
9
|
+
@default_value = false
|
9
10
|
end
|
10
11
|
|
11
12
|
# Given the argument list, scans it looking for this switch
|
12
13
|
# returning true if it's in the argumennt list (and removing it from the argument list)
|
13
14
|
def get_value!(args)
|
14
15
|
idx = -1
|
15
|
-
args.each_index do |
|
16
|
-
result = find_me(args[
|
16
|
+
args.each_index do |index|
|
17
|
+
result = find_me(args[index])
|
17
18
|
if result[0]
|
18
19
|
if result[1]
|
19
|
-
args[
|
20
|
+
args[index] = result[1]
|
20
21
|
else
|
21
|
-
args.delete_at
|
22
|
+
args.delete_at index
|
22
23
|
end
|
23
24
|
return result[0]
|
24
25
|
end
|
25
26
|
end
|
26
|
-
|
27
|
+
@default_value
|
28
|
+
end
|
29
|
+
|
30
|
+
# Used only to configure what's returned if we do not detect this switch on the command line
|
31
|
+
# This allows the configuration file to set a switch as always on
|
32
|
+
def default_value=(default)
|
33
|
+
@default_value = default
|
27
34
|
end
|
28
35
|
|
29
36
|
# Finds the switch in the given arg, returning the arg to keep.
|
data/lib/gli/terminal.rb
CHANGED
@@ -43,7 +43,7 @@ module GLI
|
|
43
43
|
#
|
44
44
|
# +command+:: The command, as a String, to check for, without any path information.
|
45
45
|
def command_exists?(command)
|
46
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).any? {|
|
46
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).any? {|dir| File.exists? File.join(dir, command) }
|
47
47
|
end
|
48
48
|
|
49
49
|
# Get the size of the current terminal.
|
@@ -56,7 +56,7 @@ module GLI
|
|
56
56
|
elsif (jruby? || (!STDIN.tty? && ENV['TERM'])) && command_exists?('tput')
|
57
57
|
[run_command('tput cols').to_i, run_command('tput lines').to_i]
|
58
58
|
elsif STDIN.tty? && command_exists?('stty')
|
59
|
-
run_command('stty size').scan(/\d+/).map { |
|
59
|
+
run_command('stty size').scan(/\d+/).map { |size_element| size_element.to_i }.reverse
|
60
60
|
else
|
61
61
|
Terminal.default_size
|
62
62
|
end
|
data/lib/gli_version.rb
CHANGED
data/lib/support/help.rb
CHANGED
@@ -5,9 +5,24 @@ require 'gli/terminal'
|
|
5
5
|
module GLI
|
6
6
|
class DefaultHelpCommand < Command #:nodoc:
|
7
7
|
@@output = $stdout
|
8
|
+
@@skips_pre = true
|
9
|
+
@@skips_post = true
|
10
|
+
|
8
11
|
# Exposed for testing
|
9
12
|
def self.output_device=(o); @@output = o; end
|
10
13
|
|
14
|
+
# To override the default behavior of the help command, which is
|
15
|
+
# to NOT run the pre block, use this.
|
16
|
+
def self.skips_pre=(skips_pre)
|
17
|
+
@@skips_pre = skips_pre
|
18
|
+
end
|
19
|
+
|
20
|
+
# To override the default behavior of the help command, which is
|
21
|
+
# to NOT run the post block, use this.
|
22
|
+
def self.skips_post=(skips_post)
|
23
|
+
@@skips_post = skips_post
|
24
|
+
end
|
25
|
+
|
11
26
|
def initialize(version,*omit_from_list)
|
12
27
|
@omit_from_list = omit_from_list
|
13
28
|
@version = version
|
@@ -19,6 +34,9 @@ module GLI
|
|
19
34
|
self.switch [:c,:completion]
|
20
35
|
end
|
21
36
|
|
37
|
+
def skips_pre; @@skips_pre; end
|
38
|
+
def skips_post; @@skips_post; end
|
39
|
+
|
22
40
|
def execute(global_options,options,arguments)
|
23
41
|
if options[:c]
|
24
42
|
names = commands_to_show.reduce([]) do |memo,obj|
|
@@ -47,6 +65,10 @@ module GLI
|
|
47
65
|
private
|
48
66
|
|
49
67
|
def list_global_flags
|
68
|
+
if GLI.program_desc
|
69
|
+
@@output.puts wrap(GLI.program_desc,0)
|
70
|
+
@@output.puts
|
71
|
+
end
|
50
72
|
usage = "usage: #{GLI.program_name} "
|
51
73
|
all_options = GLI.switches.merge(GLI.flags)
|
52
74
|
if !all_options.empty?
|
data/lib/support/rdoc.rb
CHANGED
@@ -48,6 +48,10 @@ module GLI
|
|
48
48
|
def create_rdoc
|
49
49
|
File.open("#{GLI.program_name}.rdoc",'w') do |file|
|
50
50
|
file << "= <tt>#{GLI.program_name}</tt>\n\n"
|
51
|
+
if GLI.program_desc
|
52
|
+
file << GLI.program_desc
|
53
|
+
file << "\n\n"
|
54
|
+
end
|
51
55
|
file << " "
|
52
56
|
file << GLI.program_name
|
53
57
|
file << " "
|
data/lib/support/scaffold.rb
CHANGED
@@ -115,7 +115,6 @@ EOS
|
|
115
115
|
File.open("#{root_dir}/#{project_name}/test/tc_nothing.rb",'w') do |test_file|
|
116
116
|
test_file.puts <<EOS
|
117
117
|
require 'test/unit'
|
118
|
-
require 'test/unit/ui/console/testrunner'
|
119
118
|
|
120
119
|
class TC_testNothing < Test::Unit::TestCase
|
121
120
|
|
@@ -173,6 +172,8 @@ require '#{project_name}_version'
|
|
173
172
|
|
174
173
|
include GLI
|
175
174
|
|
175
|
+
program_desc 'Describe your application here'
|
176
|
+
|
176
177
|
version #{project_name_as_module_name(project_name)}::VERSION
|
177
178
|
|
178
179
|
desc 'Describe some switch here'
|
@@ -224,11 +225,15 @@ pre do |global,command,options,args|
|
|
224
225
|
# Pre logic here
|
225
226
|
# Return true to proceed; false to abourt and not call the
|
226
227
|
# chosen command
|
228
|
+
# Use skips_pre before a command to skip this block
|
229
|
+
# on that command only
|
227
230
|
true
|
228
231
|
end
|
229
232
|
|
230
233
|
post do |global,command,options,args|
|
231
234
|
# Post logic here
|
235
|
+
# Use skips_post before a command to skip this
|
236
|
+
# block on that command only
|
232
237
|
end
|
233
238
|
|
234
239
|
on_error do |exception|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 1.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- David Copeland
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-05-01 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -23,73 +23,120 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
- 8
|
31
|
-
-
|
32
|
-
version: 0.8.
|
31
|
+
- 0
|
32
|
+
version: 0.8.0
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: rdoc
|
37
37
|
prerelease: false
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
segments:
|
44
|
+
- 2
|
45
|
+
- 4
|
44
46
|
- 0
|
45
|
-
|
46
|
-
- 8
|
47
|
-
version: 0.9.8
|
47
|
+
version: 2.4.0
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
|
-
name:
|
51
|
+
name: sdoc
|
52
52
|
prerelease: false
|
53
53
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
54
|
none: false
|
55
55
|
requirements:
|
56
|
-
- -
|
56
|
+
- - ~>
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
segments:
|
59
|
+
- 0
|
59
60
|
- 2
|
60
|
-
-
|
61
|
-
|
62
|
-
version: 2.4.3
|
61
|
+
- 0
|
62
|
+
version: 0.2.0
|
63
63
|
type: :development
|
64
64
|
version_requirements: *id003
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
66
|
+
name: reek
|
67
67
|
prerelease: false
|
68
68
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
69
|
none: false
|
70
70
|
requirements:
|
71
|
-
- -
|
71
|
+
- - ~>
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
segments:
|
74
|
-
-
|
74
|
+
- 1
|
75
75
|
- 2
|
76
|
-
-
|
77
|
-
version:
|
76
|
+
- 0
|
77
|
+
version: 1.2.0
|
78
78
|
type: :development
|
79
79
|
version_requirements: *id004
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
|
-
name:
|
81
|
+
name: roodi
|
82
82
|
prerelease: false
|
83
83
|
requirement: &id005 !ruby/object:Gem::Requirement
|
84
84
|
none: false
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - ~>
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
segments:
|
89
|
+
- 2
|
90
|
+
- 1
|
89
91
|
- 0
|
90
|
-
version:
|
92
|
+
version: 2.1.0
|
91
93
|
type: :development
|
92
94
|
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: grancher
|
97
|
+
prerelease: false
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
- 1
|
106
|
+
- 5
|
107
|
+
version: 0.1.5
|
108
|
+
type: :development
|
109
|
+
version_requirements: *id006
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rainbow
|
112
|
+
prerelease: false
|
113
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
segments:
|
119
|
+
- 1
|
120
|
+
- 1
|
121
|
+
- 1
|
122
|
+
version: 1.1.1
|
123
|
+
type: :development
|
124
|
+
version_requirements: *id007
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: aruba
|
127
|
+
prerelease: false
|
128
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
- 3
|
136
|
+
- 6
|
137
|
+
version: 0.3.6
|
138
|
+
type: :development
|
139
|
+
version_requirements: *id008
|
93
140
|
description: An application and API for describing command line interfaces that can be used to quickly create a shell for executing command-line tasks. The command line user interface is similar to Gits, in that it takes global options, a command, command-specific options, and arguments
|
94
141
|
email: davidcopeland@naildrivin5.com
|
95
142
|
executables:
|
@@ -102,6 +149,7 @@ extra_rdoc_files:
|
|
102
149
|
files:
|
103
150
|
- lib/gli/command.rb
|
104
151
|
- lib/gli/command_line_token.rb
|
152
|
+
- lib/gli/copy_options_to_aliases.rb
|
105
153
|
- lib/gli/flag.rb
|
106
154
|
- lib/gli/switch.rb
|
107
155
|
- lib/gli/options.rb
|