gli 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gli.rb +29 -16
- data/lib/gli_version.rb +1 -1
- data/lib/support/help.rb +20 -22
- data/lib/support/scaffold.rb +2 -0
- metadata +75 -133
data/lib/gli.rb
CHANGED
@@ -29,6 +29,7 @@ module GLI
|
|
29
29
|
@@program_desc = nil
|
30
30
|
@@skips_pre = false
|
31
31
|
@@skips_post = false
|
32
|
+
@@default_command = :help
|
32
33
|
|
33
34
|
# Override the device of stderr; exposed only for testing
|
34
35
|
def error_device=(e) #:nodoc:
|
@@ -44,12 +45,24 @@ module GLI
|
|
44
45
|
@@config_file = nil
|
45
46
|
@@use_openstruct = false
|
46
47
|
@@prog_desc = nil
|
48
|
+
@@default_command = :help
|
47
49
|
clear_nexts
|
48
50
|
|
49
51
|
desc 'Show this message'
|
50
52
|
switch :help
|
51
53
|
end
|
52
54
|
|
55
|
+
# Sets a default command to run when none is specified on the command line. Note that
|
56
|
+
# if you use this, you won't be able to pass arguments, flags, or switches
|
57
|
+
# to the command when run in default mode. All flags and switches are treated
|
58
|
+
# as global, and any argument will be interpretted as the command name and likely
|
59
|
+
# fail.
|
60
|
+
#
|
61
|
+
# +command+:: Command to run as default
|
62
|
+
def default_command(command)
|
63
|
+
@@default_command = command.to_sym
|
64
|
+
end
|
65
|
+
|
53
66
|
# Describe the next switch, flag, or command. This should be a
|
54
67
|
# short, one-line description
|
55
68
|
#
|
@@ -60,7 +73,7 @@ module GLI
|
|
60
73
|
# of what your program does that will appear in the help output.
|
61
74
|
#
|
62
75
|
# +description+:: A String of the short description of your program's purpose
|
63
|
-
def program_desc(description=nil)
|
76
|
+
def program_desc(description=nil)
|
64
77
|
if description
|
65
78
|
@@program_desc = description
|
66
79
|
end
|
@@ -140,7 +153,7 @@ module GLI
|
|
140
153
|
clear_nexts
|
141
154
|
end
|
142
155
|
|
143
|
-
# Sets that this app uses a config file as well as the name of the config file.
|
156
|
+
# Sets that this app uses a config file as well as the name of the config file.
|
144
157
|
#
|
145
158
|
# +filename+:: A String representing the path to the file to use for the config file. If it's an absolute
|
146
159
|
# path, this is treated as the path to the file. If it's *not*, it's treated as relative to the user's home
|
@@ -187,7 +200,7 @@ module GLI
|
|
187
200
|
# Define a block to run if an error occurs.
|
188
201
|
# The block will receive any Exception that was caught.
|
189
202
|
# It should evaluate to false to avoid the built-in error handling (which basically just
|
190
|
-
# prints out a message). GLI uses a variety of exceptions that you can use to find out what
|
203
|
+
# prints out a message). GLI uses a variety of exceptions that you can use to find out what
|
191
204
|
# errors might've occurred during command-line parsing:
|
192
205
|
# * GLI::CustomExit
|
193
206
|
# * GLI::UnknownCommandArgument
|
@@ -200,7 +213,7 @@ module GLI
|
|
200
213
|
|
201
214
|
# Indicate the version of your application
|
202
215
|
#
|
203
|
-
# +version+:: String containing the version of your application.
|
216
|
+
# +version+:: String containing the version of your application.
|
204
217
|
def version(version)
|
205
218
|
@@version = version
|
206
219
|
end
|
@@ -215,7 +228,7 @@ module GLI
|
|
215
228
|
@@use_openstruct = use_openstruct
|
216
229
|
end
|
217
230
|
|
218
|
-
# Runs whatever command is needed based on the arguments.
|
231
|
+
# Runs whatever command is needed based on the arguments.
|
219
232
|
#
|
220
233
|
# +args+:: the command line ARGV array
|
221
234
|
#
|
@@ -233,7 +246,7 @@ module GLI
|
|
233
246
|
global_options = convert_to_openstruct?(global_options)
|
234
247
|
options = convert_to_openstruct?(options)
|
235
248
|
if proceed?(global_options,command,options,arguments)
|
236
|
-
command = commands[
|
249
|
+
command = commands[@@default_command] if !command
|
237
250
|
command.execute(global_options,options,arguments)
|
238
251
|
if !command.skips_post && @@post_block
|
239
252
|
@@post_block.call(global_options,command,options,arguments)
|
@@ -258,8 +271,8 @@ module GLI
|
|
258
271
|
def proceed?(global_options,command,options,arguments) #:nodoc:
|
259
272
|
if command && command.skips_pre
|
260
273
|
true
|
261
|
-
elsif @@pre_block
|
262
|
-
@@pre_block.call(global_options,command,options,arguments)
|
274
|
+
elsif @@pre_block
|
275
|
+
@@pre_block.call(global_options,command,options,arguments)
|
263
276
|
else
|
264
277
|
true
|
265
278
|
end
|
@@ -290,7 +303,7 @@ module GLI
|
|
290
303
|
msg
|
291
304
|
end
|
292
305
|
|
293
|
-
# Simpler means of exiting with a custom exit code. This will
|
306
|
+
# Simpler means of exiting with a custom exit code. This will
|
294
307
|
# raise a CustomExit with the given message and exit code, which will ultimatley
|
295
308
|
# cause your application to exit with the given exit_code as its exit status
|
296
309
|
def exit_now!(message,exit_code)
|
@@ -343,7 +356,7 @@ module GLI
|
|
343
356
|
|
344
357
|
# Returns an array of four values:
|
345
358
|
# * global options (as a Hash)
|
346
|
-
# * Command
|
359
|
+
# * Command
|
347
360
|
# * command options (as a Hash)
|
348
361
|
# * arguments (as an Array)
|
349
362
|
def parse_options(args) # :nodoc:
|
@@ -442,7 +455,7 @@ module GLI
|
|
442
455
|
try_me = args[0..non_flag_i]
|
443
456
|
rest = args[(non_flag_i+1)..args.length]
|
444
457
|
if all_flags
|
445
|
-
try_me = args
|
458
|
+
try_me = args
|
446
459
|
rest = []
|
447
460
|
end
|
448
461
|
|
@@ -468,7 +481,7 @@ module GLI
|
|
468
481
|
# it, we want to override it with the real value.
|
469
482
|
# HOWEVER, sometimes this happens in reverse, so we want to err on taking the
|
470
483
|
# user-provided, non-default value where possible.
|
471
|
-
if value
|
484
|
+
if value
|
472
485
|
if options[name]
|
473
486
|
options[name] = value if options[name] == flag.default_value
|
474
487
|
else
|
@@ -485,13 +498,13 @@ module GLI
|
|
485
498
|
else
|
486
499
|
if command
|
487
500
|
check = rest
|
488
|
-
check = rest + try_me if all_flags
|
489
|
-
check.each() do |arg|
|
501
|
+
check = rest + try_me if all_flags
|
502
|
+
check.each() do |arg|
|
490
503
|
if arg =~ /^\-\-$/
|
491
504
|
try_me.delete arg
|
492
|
-
break
|
505
|
+
break
|
493
506
|
end
|
494
|
-
raise UnknownCommandArgument.new("Unknown option #{arg}",command) if arg =~ /^\-/
|
507
|
+
raise UnknownCommandArgument.new("Unknown option #{arg}",command) if arg =~ /^\-/
|
495
508
|
end
|
496
509
|
return [global_options,command,command_options,try_me + rest]
|
497
510
|
else
|
data/lib/gli_version.rb
CHANGED
data/lib/support/help.rb
CHANGED
@@ -150,32 +150,30 @@ module GLI
|
|
150
150
|
line_length = Terminal.instance.size[0]
|
151
151
|
end
|
152
152
|
line_padding = sprintf("%#{pad_length}s",'')
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
while wrapped.length + line_padding.length < line_length
|
157
|
-
wrapped += ' ' if wrapped.length > 0
|
158
|
-
word = words.shift
|
159
|
-
if (wrapped.length + line_padding.length + word.length > line_length)
|
160
|
-
words.unshift word
|
161
|
-
break;
|
162
|
-
end
|
163
|
-
wrapped += word
|
164
|
-
return wrapped if words.empty?
|
153
|
+
paragraphs = line.split("\n\n").map { |l| l.chomp }.reject { |l| l.empty? }
|
154
|
+
wrapped = paragraphs.map do |para|
|
155
|
+
paragraph_lines(para, line_length - pad_length).join("\n#{line_padding}")
|
165
156
|
end
|
166
|
-
wrapped
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
157
|
+
wrapped.join("\n\n#{line_padding}")
|
158
|
+
end
|
159
|
+
|
160
|
+
# Creates lines of the given column length using the words from the
|
161
|
+
# provided paragraph.
|
162
|
+
def paragraph_lines(paragraph,line_length)
|
163
|
+
lines = []
|
164
|
+
this_line = ''
|
165
|
+
|
166
|
+
paragraph.split(/\s+/).each do |word|
|
167
|
+
if this_line.length + word.length + 1 > line_length
|
168
|
+
lines << this_line
|
169
|
+
this_line = word
|
173
170
|
else
|
174
|
-
this_line += ' '
|
171
|
+
this_line += ' ' unless this_line.empty?
|
175
172
|
this_line += word
|
176
173
|
end
|
177
174
|
end
|
178
|
-
|
179
|
-
|
175
|
+
|
176
|
+
lines << this_line
|
180
177
|
end
|
178
|
+
|
181
179
|
end
|
data/lib/support/scaffold.rb
CHANGED
@@ -51,6 +51,7 @@ spec = Gem::Specification.new do |s|
|
|
51
51
|
# Add your other files here if you make them
|
52
52
|
s.files = %w(
|
53
53
|
bin/#{project_name}
|
54
|
+
lib/#{project_name}_version.rb
|
54
55
|
)
|
55
56
|
s.require_paths << 'lib'
|
56
57
|
s.has_rdoc = true
|
@@ -60,6 +61,7 @@ bin/#{project_name}
|
|
60
61
|
s.executables << '#{project_name}'
|
61
62
|
s.add_development_dependency('rake')
|
62
63
|
s.add_development_dependency('rdoc')
|
64
|
+
s.add_runtime_dependency('gli')
|
63
65
|
end
|
64
66
|
EOS
|
65
67
|
end
|
metadata
CHANGED
@@ -1,188 +1,133 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
name:
|
3
|
-
Z2xp
|
2
|
+
name: gli
|
4
3
|
version: !ruby/object:Gem::Version
|
5
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
6
5
|
prerelease:
|
7
6
|
platform: ruby
|
8
7
|
authors:
|
9
|
-
-
|
10
|
-
RGF2aWQgQ29wZWxhbmQ=
|
8
|
+
- David Copeland
|
11
9
|
autorequire:
|
12
|
-
bindir:
|
13
|
-
Ymlu
|
10
|
+
bindir: bin
|
14
11
|
cert_chain: []
|
15
|
-
date: 2012-
|
12
|
+
date: 2012-04-09 00:00:00.000000000Z
|
16
13
|
dependencies:
|
17
14
|
- !ruby/object:Gem::Dependency
|
18
|
-
name:
|
19
|
-
|
20
|
-
requirement: &70298245125980 !ruby/object:Gem::Requirement
|
15
|
+
name: rake
|
16
|
+
requirement: &70269061967140 !ruby/object:Gem::Requirement
|
21
17
|
none: false
|
22
18
|
requirements:
|
23
|
-
- -
|
24
|
-
fj4=
|
19
|
+
- - ~>
|
25
20
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
MC45LjIuMg==
|
21
|
+
version: 0.9.2.2
|
28
22
|
type: :development
|
29
23
|
prerelease: false
|
30
|
-
version_requirements: *
|
24
|
+
version_requirements: *70269061967140
|
31
25
|
- !ruby/object:Gem::Dependency
|
32
|
-
name:
|
33
|
-
|
34
|
-
requirement: &70298245125280 !ruby/object:Gem::Requirement
|
26
|
+
name: rdoc
|
27
|
+
requirement: &70269061966560 !ruby/object:Gem::Requirement
|
35
28
|
none: false
|
36
29
|
requirements:
|
37
|
-
- -
|
38
|
-
fj4=
|
30
|
+
- - ~>
|
39
31
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
My4xMQ==
|
32
|
+
version: '3.11'
|
42
33
|
type: :development
|
43
34
|
prerelease: false
|
44
|
-
version_requirements: *
|
35
|
+
version_requirements: *70269061966560
|
45
36
|
- !ruby/object:Gem::Dependency
|
46
|
-
name:
|
47
|
-
|
48
|
-
requirement: &70298245124700 !ruby/object:Gem::Requirement
|
37
|
+
name: reek
|
38
|
+
requirement: &70269061965940 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
40
|
requirements:
|
51
|
-
- -
|
52
|
-
fj4=
|
41
|
+
- - ~>
|
53
42
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
MS4yLjA=
|
43
|
+
version: 1.2.0
|
56
44
|
type: :development
|
57
45
|
prerelease: false
|
58
|
-
version_requirements: *
|
46
|
+
version_requirements: *70269061965940
|
59
47
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
61
|
-
|
62
|
-
requirement: &70298245123940 !ruby/object:Gem::Requirement
|
48
|
+
name: roodi
|
49
|
+
requirement: &70269061965300 !ruby/object:Gem::Requirement
|
63
50
|
none: false
|
64
51
|
requirements:
|
65
|
-
- -
|
66
|
-
fj4=
|
52
|
+
- - ~>
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
69
|
-
Mi4xLjA=
|
54
|
+
version: 2.1.0
|
70
55
|
type: :development
|
71
56
|
prerelease: false
|
72
|
-
version_requirements: *
|
57
|
+
version_requirements: *70269061965300
|
73
58
|
- !ruby/object:Gem::Dependency
|
74
|
-
name:
|
75
|
-
|
76
|
-
requirement: &70298245123160 !ruby/object:Gem::Requirement
|
59
|
+
name: grancher
|
60
|
+
requirement: &70269061964780 !ruby/object:Gem::Requirement
|
77
61
|
none: false
|
78
62
|
requirements:
|
79
|
-
- -
|
80
|
-
fj4=
|
63
|
+
- - ~>
|
81
64
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
83
|
-
MC4xLjU=
|
65
|
+
version: 0.1.5
|
84
66
|
type: :development
|
85
67
|
prerelease: false
|
86
|
-
version_requirements: *
|
68
|
+
version_requirements: *70269061964780
|
87
69
|
- !ruby/object:Gem::Dependency
|
88
|
-
name:
|
89
|
-
|
90
|
-
requirement: &70298245122480 !ruby/object:Gem::Requirement
|
70
|
+
name: rainbow
|
71
|
+
requirement: &70269061964240 !ruby/object:Gem::Requirement
|
91
72
|
none: false
|
92
73
|
requirements:
|
93
|
-
- -
|
94
|
-
fj4=
|
74
|
+
- - ~>
|
95
75
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
97
|
-
MS4xLjE=
|
76
|
+
version: 1.1.1
|
98
77
|
type: :development
|
99
78
|
prerelease: false
|
100
|
-
version_requirements: *
|
79
|
+
version_requirements: *70269061964240
|
101
80
|
- !ruby/object:Gem::Dependency
|
102
|
-
name:
|
103
|
-
|
104
|
-
requirement: &70298245121760 !ruby/object:Gem::Requirement
|
81
|
+
name: aruba
|
82
|
+
requirement: &70269061896020 !ruby/object:Gem::Requirement
|
105
83
|
none: false
|
106
84
|
requirements:
|
107
|
-
- -
|
108
|
-
fj4=
|
85
|
+
- - ~>
|
109
86
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
111
|
-
MC40Ljc=
|
87
|
+
version: 0.4.7
|
112
88
|
type: :development
|
113
89
|
prerelease: false
|
114
|
-
version_requirements: *
|
115
|
-
description:
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
YXIgdG8gR2l0cywgaW4gdGhhdCBpdCB0YWtlcyBnbG9iYWwgb3B0aW9ucywg
|
121
|
-
YSBjb21tYW5kLCBjb21tYW5kLXNwZWNpZmljIG9wdGlvbnMsIGFuZCBhcmd1
|
122
|
-
bWVudHM=
|
123
|
-
email: !binary |-
|
124
|
-
ZGF2aWRjb3BlbGFuZEBuYWlsZHJpdmluNS5jb20=
|
90
|
+
version_requirements: *70269061896020
|
91
|
+
description: An application and API for describing command line interfaces that can
|
92
|
+
be used to quickly create a shell for executing command-line tasks. The command
|
93
|
+
line user interface is similar to Gits, in that it takes global options, a command,
|
94
|
+
command-specific options, and arguments
|
95
|
+
email: davidcopeland@naildrivin5.com
|
125
96
|
executables:
|
126
|
-
-
|
127
|
-
Z2xp
|
97
|
+
- gli
|
128
98
|
extensions: []
|
129
99
|
extra_rdoc_files:
|
130
|
-
-
|
131
|
-
|
132
|
-
- !binary |-
|
133
|
-
Z2xpLnJkb2M=
|
100
|
+
- README.rdoc
|
101
|
+
- gli.rdoc
|
134
102
|
files:
|
135
|
-
-
|
136
|
-
|
137
|
-
-
|
138
|
-
|
139
|
-
-
|
140
|
-
|
141
|
-
-
|
142
|
-
|
143
|
-
-
|
144
|
-
|
145
|
-
-
|
146
|
-
|
147
|
-
-
|
148
|
-
|
149
|
-
-
|
150
|
-
|
151
|
-
-
|
152
|
-
|
153
|
-
- !binary |-
|
154
|
-
bGliL2dsaV92ZXJzaW9uLnJi
|
155
|
-
- !binary |-
|
156
|
-
bGliL3N1cHBvcnQvaGVscC5yYg==
|
157
|
-
- !binary |-
|
158
|
-
bGliL3N1cHBvcnQvcmRvYy5yYg==
|
159
|
-
- !binary |-
|
160
|
-
bGliL3N1cHBvcnQvc2NhZmZvbGQucmI=
|
161
|
-
- !binary |-
|
162
|
-
bGliL3N1cHBvcnQvaW5pdGNvbmZpZy5yYg==
|
163
|
-
- !binary |-
|
164
|
-
YmluL2dsaQ==
|
165
|
-
- !binary |-
|
166
|
-
UkVBRE1FLnJkb2M=
|
167
|
-
- !binary |-
|
168
|
-
Z2xpLnJkb2M=
|
169
|
-
homepage: !binary |-
|
170
|
-
aHR0cDovL2RhdmV0cm9uNTAwMC5naXRodWIuY29tL2dsaQ==
|
103
|
+
- lib/gli/command.rb
|
104
|
+
- lib/gli/command_line_token.rb
|
105
|
+
- lib/gli/copy_options_to_aliases.rb
|
106
|
+
- lib/gli/flag.rb
|
107
|
+
- lib/gli/switch.rb
|
108
|
+
- lib/gli/options.rb
|
109
|
+
- lib/gli/exceptions.rb
|
110
|
+
- lib/gli/terminal.rb
|
111
|
+
- lib/gli.rb
|
112
|
+
- lib/gli_version.rb
|
113
|
+
- lib/support/help.rb
|
114
|
+
- lib/support/rdoc.rb
|
115
|
+
- lib/support/scaffold.rb
|
116
|
+
- lib/support/initconfig.rb
|
117
|
+
- bin/gli
|
118
|
+
- README.rdoc
|
119
|
+
- gli.rdoc
|
120
|
+
homepage: http://davetron5000.github.com/gli
|
171
121
|
licenses: []
|
172
122
|
post_install_message:
|
173
123
|
rdoc_options:
|
174
|
-
-
|
175
|
-
|
176
|
-
-
|
177
|
-
|
178
|
-
- !binary |-
|
179
|
-
LS1tYWlu
|
180
|
-
- !binary |-
|
181
|
-
UkVBRE1FLnJkb2M=
|
124
|
+
- --title
|
125
|
+
- Git Like Interface
|
126
|
+
- --main
|
127
|
+
- README.rdoc
|
182
128
|
require_paths:
|
183
129
|
- lib
|
184
|
-
-
|
185
|
-
bGli
|
130
|
+
- lib
|
186
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
187
132
|
none: false
|
188
133
|
requirements:
|
@@ -191,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
191
136
|
version: '0'
|
192
137
|
segments:
|
193
138
|
- 0
|
194
|
-
hash:
|
139
|
+
hash: -3214351787275830697
|
195
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
141
|
none: false
|
197
142
|
requirements:
|
@@ -200,14 +145,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
145
|
version: '0'
|
201
146
|
segments:
|
202
147
|
- 0
|
203
|
-
hash:
|
148
|
+
hash: -3214351787275830697
|
204
149
|
requirements: []
|
205
|
-
rubyforge_project:
|
206
|
-
Z2xp
|
150
|
+
rubyforge_project: gli
|
207
151
|
rubygems_version: 1.8.10
|
208
152
|
signing_key:
|
209
153
|
specification_version: 3
|
210
|
-
summary:
|
211
|
-
QSBHaXQgTGlrZSBJbnRlcmZhY2UgZm9yIGJ1aWxkaW5nIGNvbW1hbmQgbGlu
|
212
|
-
ZSBhcHBz
|
154
|
+
summary: A Git Like Interface for building command line apps
|
213
155
|
test_files: []
|