claide 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/claide.rb +5 -5
- data/lib/claide/argv.rb +2 -0
- data/lib/claide/command.rb +154 -42
- data/lib/claide/command/banner.rb +76 -9
- data/lib/claide/help.rb +23 -6
- data/lib/claide/informative_error.rb +2 -0
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c48ac46a6dd1a3d4b6e9b31d6e7e0a9b4697ecc7
|
4
|
+
data.tar.gz: aafaf22c16450580a41154a005103b321654fddf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f2a2db1a5e9632761d90bd3486376fe856b6f4012f69391ea093b810c3883cd1f8b9b1b271f42bec2b3b105ba2ef3a14adf1a07ec2fa45f97edb6785f0dedaf
|
7
|
+
data.tar.gz: ee607530bb899f4a376bcb6a262a9dbf8bd7790cf85a568f99234ad156249f23e38f5f2cd9f364da6c626ef9fba0501c0c8277b9508cce99cc34f835462288cc
|
data/lib/claide.rb
CHANGED
@@ -9,11 +9,11 @@ module CLAide
|
|
9
9
|
#
|
10
10
|
# CLAide’s version, following [semver](http://semver.org).
|
11
11
|
#
|
12
|
-
VERSION = '0.
|
12
|
+
VERSION = '0.5.0'
|
13
13
|
|
14
|
-
require 'claide/argv
|
15
|
-
require 'claide/command
|
16
|
-
require 'claide/help
|
17
|
-
require 'claide/informative_error
|
14
|
+
require 'claide/argv'
|
15
|
+
require 'claide/command'
|
16
|
+
require 'claide/help'
|
17
|
+
require 'claide/informative_error'
|
18
18
|
|
19
19
|
end
|
data/lib/claide/argv.rb
CHANGED
data/lib/claide/command.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'claide/command/banner'
|
2
4
|
|
3
5
|
module CLAide
|
@@ -53,6 +55,17 @@ module CLAide
|
|
53
55
|
attr_accessor :abstract_command
|
54
56
|
alias_method :abstract_command?, :abstract_command
|
55
57
|
|
58
|
+
# @return [Boolean] Indicates whether or not this command is used during
|
59
|
+
# command parsing and whether or not it should be shown in the
|
60
|
+
# help banner or to show its subcommands instead.
|
61
|
+
#
|
62
|
+
# Setting this to `true` implies it’s an abstract command.
|
63
|
+
attr_reader :ignore_in_command_lookup
|
64
|
+
alias_method :ignore_in_command_lookup?, :ignore_in_command_lookup
|
65
|
+
def ignore_in_command_lookup=(flag)
|
66
|
+
@ignore_in_command_lookup = self.abstract_command = flag
|
67
|
+
end
|
68
|
+
|
56
69
|
# @return [String] The subcommand which an abstract command should invoke
|
57
70
|
# by default.
|
58
71
|
#
|
@@ -80,21 +93,39 @@ module CLAide
|
|
80
93
|
#
|
81
94
|
attr_accessor :arguments
|
82
95
|
|
83
|
-
# @return [Boolean] The default value for {Command#
|
84
|
-
# defaults to `true` if `
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
96
|
+
# @return [Boolean] The default value for {Command#ansi_output}. This
|
97
|
+
# defaults to `true` if `STDOUT` is connected to a TTY and
|
98
|
+
# `String` has the instance methods `#red`, `#green`, and
|
99
|
+
# `#yellow` (which are defined by, for instance, the
|
100
|
+
# [colored](https://github.com/defunkt/colored) gem).
|
101
|
+
#
|
102
|
+
def ansi_output
|
103
|
+
if @ansi_output.nil?
|
104
|
+
@ansi_output = STDOUT.tty? &&
|
105
|
+
String.method_defined?(:red) &&
|
106
|
+
String.method_defined?(:green) &&
|
107
|
+
String.method_defined?(:yellow)
|
92
108
|
end
|
93
|
-
@
|
109
|
+
@ansi_output
|
110
|
+
end
|
111
|
+
attr_writer :ansi_output
|
112
|
+
alias_method :ansi_output?, :ansi_output
|
113
|
+
|
114
|
+
def colorize_output
|
115
|
+
warn "[!] The use of `CLAide::Command.colorize_output` has been " \
|
116
|
+
"deprecated. Use `CLAide::Command.ansi_output` instead. " \
|
117
|
+
"(Called from: #{caller.first})"
|
118
|
+
ansi_output
|
94
119
|
end
|
95
|
-
attr_writer :colorize_output
|
96
120
|
alias_method :colorize_output?, :colorize_output
|
97
121
|
|
122
|
+
def colorize_output=(flag)
|
123
|
+
warn "[!] The use of `CLAide::Command.colorize_output=` has been " \
|
124
|
+
"deprecated. Use `CLAide::Command.ansi_output=` instead. " \
|
125
|
+
"(Called from: #{caller.first})"
|
126
|
+
self.ansi_output = flag
|
127
|
+
end
|
128
|
+
|
98
129
|
# @return [String] The name of the command. Defaults to a snake-cased
|
99
130
|
# version of the class’ name.
|
100
131
|
#
|
@@ -105,7 +136,10 @@ module CLAide
|
|
105
136
|
end
|
106
137
|
attr_writer :command
|
107
138
|
|
108
|
-
# @return [String] The full command up-to this command
|
139
|
+
# @return [String] The full command up-to this command, as it would be
|
140
|
+
# looked up during parsing.
|
141
|
+
#
|
142
|
+
# @note (see #ignore_in_command_lookup)
|
109
143
|
#
|
110
144
|
# @example
|
111
145
|
#
|
@@ -113,19 +147,49 @@ module CLAide
|
|
113
147
|
#
|
114
148
|
def full_command
|
115
149
|
if superclass == Command
|
116
|
-
|
150
|
+
ignore_in_command_lookup? ? '' : command
|
117
151
|
else
|
118
|
-
|
152
|
+
if ignore_in_command_lookup?
|
153
|
+
superclass.full_command
|
154
|
+
else
|
155
|
+
"#{superclass.full_command} #{command}"
|
156
|
+
end
|
119
157
|
end
|
120
158
|
end
|
121
159
|
|
122
|
-
# @return [Array<Class>] A list of command classes that are nested
|
123
|
-
# this command.
|
160
|
+
# @return [Array<Class>] A list of all command classes that are nested
|
161
|
+
# under this command.
|
124
162
|
#
|
125
163
|
def subcommands
|
126
164
|
@subcommands ||= []
|
127
165
|
end
|
128
166
|
|
167
|
+
# @return [Array<Class>] A list of command classes that are nested under
|
168
|
+
# this command _or_ the subcommands of those command classes in
|
169
|
+
# case the command class should be ignored in command lookup.
|
170
|
+
#
|
171
|
+
def subcommands_for_command_lookup
|
172
|
+
subcommands.map do |subcommand|
|
173
|
+
if subcommand.ignore_in_command_lookup?
|
174
|
+
subcommand.subcommands_for_command_lookup
|
175
|
+
else
|
176
|
+
subcommand
|
177
|
+
end
|
178
|
+
end.flatten
|
179
|
+
end
|
180
|
+
|
181
|
+
# Searches the list of subcommands that should not be ignored for command
|
182
|
+
# lookup for a subcommand with the given `name`.
|
183
|
+
#
|
184
|
+
# @param [String] name
|
185
|
+
# The name of the subcommand to be found.
|
186
|
+
#
|
187
|
+
# @return [CLAide::Command, nil] The subcommand, if found.
|
188
|
+
#
|
189
|
+
def find_subcommand(name)
|
190
|
+
subcommands_for_command_lookup.find { |sc| sc.command == name }
|
191
|
+
end
|
192
|
+
|
129
193
|
# @visibility private
|
130
194
|
#
|
131
195
|
# Automatically registers a subclass as a subcommand.
|
@@ -158,8 +222,8 @@ module CLAide
|
|
158
222
|
['--verbose', 'Show more debugging information'],
|
159
223
|
['--help', 'Show help banner of specified command'],
|
160
224
|
]
|
161
|
-
if Command.
|
162
|
-
options.unshift(['--no-
|
225
|
+
if Command.ansi_output?
|
226
|
+
options.unshift(['--no-ansi', 'Show output without ANSI codes'])
|
163
227
|
end
|
164
228
|
options
|
165
229
|
end
|
@@ -174,14 +238,14 @@ module CLAide
|
|
174
238
|
def parse(argv)
|
175
239
|
argv = ARGV.new(argv) unless argv.is_a?(ARGV)
|
176
240
|
cmd = argv.arguments.first
|
177
|
-
if cmd && subcommand =
|
241
|
+
if cmd && subcommand = find_subcommand(cmd)
|
178
242
|
argv.shift_argument
|
179
243
|
subcommand.parse(argv)
|
180
244
|
elsif abstract_command? && default_subcommand
|
181
|
-
subcommand =
|
245
|
+
subcommand = find_subcommand(default_subcommand)
|
182
246
|
unless subcommand
|
183
|
-
raise "Unable to find the default subcommand
|
184
|
-
|
247
|
+
raise "Unable to find the default subcommand " \
|
248
|
+
"`#{default_subcommand}` for command `#{self}`."
|
185
249
|
end
|
186
250
|
result = subcommand.parse(argv)
|
187
251
|
result.invoked_as_default = true
|
@@ -244,28 +308,40 @@ module CLAide
|
|
244
308
|
|
245
309
|
# @visibility private
|
246
310
|
#
|
247
|
-
# @
|
311
|
+
# @param [String] error_message
|
312
|
+
# The error message to show to the user.
|
313
|
+
#
|
314
|
+
# @param [Boolean] ansi_output
|
315
|
+
# Whether or not to use ANSI codes to prettify output.
|
316
|
+
#
|
317
|
+
# @param [Class] help_class
|
318
|
+
# The class to use to raise a ‘help’ error.
|
319
|
+
#
|
320
|
+
# @raise [Help]
|
248
321
|
#
|
249
322
|
# Signals CLAide that a help banner for this command should be shown,
|
250
323
|
# with an optional error message.
|
251
324
|
#
|
252
325
|
# @return [void]
|
253
326
|
#
|
254
|
-
def help!(error_message = nil,
|
255
|
-
raise
|
327
|
+
def help!(error_message = nil, ansi_output = false, help_class = Help)
|
328
|
+
raise help_class.new(banner(ansi_output), error_message, ansi_output)
|
256
329
|
end
|
257
330
|
|
258
331
|
# @visibility private
|
259
332
|
#
|
260
333
|
# Returns the banner for the command.
|
261
334
|
#
|
262
|
-
# @param [
|
263
|
-
# Whether the banner should
|
335
|
+
# @param [Boolean] ansi
|
336
|
+
# Whether the banner should use ANSI codes to prettify output.
|
337
|
+
#
|
338
|
+
# @param [Class] banner_class
|
339
|
+
# The class to use to format help banners.
|
264
340
|
#
|
265
341
|
# @return [String] The banner for the command.
|
266
342
|
#
|
267
|
-
def banner(
|
268
|
-
|
343
|
+
def banner(ansi_output = false, banner_class = Banner)
|
344
|
+
banner_class.new(self, ansi_output).formatted_banner
|
269
345
|
end
|
270
346
|
|
271
347
|
# Load additional plugins via rubygems looking for:
|
@@ -304,8 +380,20 @@ module CLAide
|
|
304
380
|
message << "\n#{exception.class} - #{exception.message}"
|
305
381
|
message << "\n#{exception.backtrace.join("\n")}"
|
306
382
|
message << "\n---------------------------------------------\n"
|
307
|
-
|
308
|
-
|
383
|
+
puts prettify_plugin_load_error(message)
|
384
|
+
end
|
385
|
+
|
386
|
+
# Override to control how to print the warning that’s shown when an
|
387
|
+
# exception occurs during plugin loading.
|
388
|
+
#
|
389
|
+
# By default this will be displayed in yellow if `#ansi_output?` returns
|
390
|
+
# `true`.
|
391
|
+
#
|
392
|
+
# @param [String] message
|
393
|
+
# The plugin load error message.
|
394
|
+
#
|
395
|
+
def prettify_plugin_load_error(message)
|
396
|
+
ansi_output? ? message.yellow : message
|
309
397
|
end
|
310
398
|
end
|
311
399
|
|
@@ -327,19 +415,35 @@ module CLAide
|
|
327
415
|
attr_accessor :verbose
|
328
416
|
alias_method :verbose?, :verbose
|
329
417
|
|
330
|
-
# Set to `true` if {Command.
|
331
|
-
# did **not** specify the `--no-
|
418
|
+
# Set to `true` if {Command.ansi_output} returns `true` and the user
|
419
|
+
# did **not** specify the `--no-ansi` option.
|
332
420
|
#
|
333
421
|
# @note (see #verbose)
|
334
422
|
#
|
335
423
|
# @return [Boolean]
|
336
424
|
#
|
337
|
-
#
|
425
|
+
# Whether or not to use ANSI codes to prettify output. For instance, by
|
426
|
+
# default {InformativeError} exception messages will be colored red and
|
338
427
|
# subcommands in help banners green.
|
339
428
|
#
|
340
|
-
attr_accessor :
|
429
|
+
attr_accessor :ansi_output
|
430
|
+
alias_method :ansi_output?, :ansi_output
|
431
|
+
|
432
|
+
def colorize_output
|
433
|
+
warn "[!] The use of `CLAide::Command#colorize_output` has been " \
|
434
|
+
"deprecated. Use `CLAide::Command#ansi_output` instead. " \
|
435
|
+
"(Called from: #{caller.first})"
|
436
|
+
ansi_output
|
437
|
+
end
|
341
438
|
alias_method :colorize_output?, :colorize_output
|
342
439
|
|
440
|
+
def colorize_output=(flag)
|
441
|
+
warn "[!] The use of `CLAide::Command#colorize_output=` has been " \
|
442
|
+
"deprecated. Use `CLAide::Command#ansi_output=` instead. " \
|
443
|
+
"(Called from: #{caller.first})"
|
444
|
+
self.ansi_output = flag
|
445
|
+
end
|
446
|
+
|
343
447
|
# @return [Bool] Whether the command was invoked by an abstract command by
|
344
448
|
# default.
|
345
449
|
#
|
@@ -350,9 +454,9 @@ module CLAide
|
|
350
454
|
# they support from `argv` _before_ calling `super`.
|
351
455
|
#
|
352
456
|
# The `super` implementation sets the {#verbose} attribute based on whether
|
353
|
-
# or not the `--verbose` option is specified; and the {#
|
354
|
-
# attribute to `false` if {Command.
|
355
|
-
# user specified the `--no-
|
457
|
+
# or not the `--verbose` option is specified; and the {#ansi_output}
|
458
|
+
# attribute to `false` if {Command.ansi_output} returns `true`, but the
|
459
|
+
# user specified the `--no-ansi` option.
|
356
460
|
#
|
357
461
|
# @param [ARGV, Array] argv
|
358
462
|
#
|
@@ -361,7 +465,15 @@ module CLAide
|
|
361
465
|
def initialize(argv)
|
362
466
|
argv = ARGV.new(argv) unless argv.is_a?(ARGV)
|
363
467
|
@verbose = argv.flag?('verbose')
|
364
|
-
@
|
468
|
+
@ansi_output = argv.flag?('ansi', Command.ansi_output?)
|
469
|
+
|
470
|
+
color = argv.flag?('color')
|
471
|
+
unless color.nil?
|
472
|
+
warn "[!] The use of the `--color`/`--no-color` flag has been " \
|
473
|
+
"deprecated. Use `--ansi`/`--no-ansi` instead."
|
474
|
+
@ansi_output = color
|
475
|
+
end
|
476
|
+
|
365
477
|
@argv = argv
|
366
478
|
end
|
367
479
|
|
@@ -388,8 +500,8 @@ module CLAide
|
|
388
500
|
# @return [void
|
389
501
|
#
|
390
502
|
def run
|
391
|
-
raise "A subclass should override the Command#run method to
|
392
|
-
"perform some work."
|
503
|
+
raise "A subclass should override the `CLAide::Command#run` method to " \
|
504
|
+
"actually perform some work."
|
393
505
|
end
|
394
506
|
|
395
507
|
protected
|
@@ -407,7 +519,7 @@ module CLAide
|
|
407
519
|
else
|
408
520
|
command = self.class
|
409
521
|
end
|
410
|
-
command = command.help!(error_message,
|
522
|
+
command = command.help!(error_message, ansi_output?)
|
411
523
|
end
|
412
524
|
|
413
525
|
#-------------------------------------------------------------------------#
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module CLAide
|
2
4
|
class Command
|
3
5
|
|
@@ -12,15 +14,30 @@ module CLAide
|
|
12
14
|
|
13
15
|
# @return [Bool]
|
14
16
|
#
|
15
|
-
attr_accessor :
|
17
|
+
attr_accessor :ansi_output
|
18
|
+
alias_method :ansi_output?, :ansi_output
|
19
|
+
|
20
|
+
def colorize_output
|
21
|
+
warn "[!] The use of `CLAide::Command::Banner#colorize_output` has " \
|
22
|
+
"been deprecated. Use `CLAide::Command::Banner#ansi_output` " \
|
23
|
+
"instead. (Called from: #{caller.first})"
|
24
|
+
ansi_output
|
25
|
+
end
|
16
26
|
alias_method :colorize_output?, :colorize_output
|
17
27
|
|
28
|
+
def colorize_output=(flag)
|
29
|
+
warn "[!] The use of `CLAide::Command::Banner#colorize_output=` has " \
|
30
|
+
"been deprecated. Use `CLAide::Command::Banner#ansi_output=` " \
|
31
|
+
"instead. (Called from: #{caller.first})"
|
32
|
+
self.ansi_output = flag
|
33
|
+
end
|
34
|
+
|
18
35
|
# @param [Class] command @see command
|
19
|
-
# @param [Class]
|
36
|
+
# @param [Class] ansi_output @see ansi_output
|
20
37
|
#
|
21
|
-
def initialize(command,
|
38
|
+
def initialize(command, ansi_output = false)
|
22
39
|
@command = command
|
23
|
-
@
|
40
|
+
@ansi_output = ansi_output
|
24
41
|
end
|
25
42
|
|
26
43
|
# @return [String]
|
@@ -52,8 +69,27 @@ module CLAide
|
|
52
69
|
#
|
53
70
|
def formatted_options_description
|
54
71
|
opts = command.options
|
55
|
-
|
56
|
-
|
72
|
+
max_key_size = opts.map { |opt| opt.first.size }.max
|
73
|
+
|
74
|
+
desc_start = max_key_size + 7 # fixed whitespace in `result` var
|
75
|
+
desc_width = terminal_width - desc_start
|
76
|
+
|
77
|
+
opts.map do |key, desc|
|
78
|
+
space = ' ' * (max_key_size - key.size)
|
79
|
+
result = " #{prettify_option_name(key)}#{space} "
|
80
|
+
if terminal_width == 0
|
81
|
+
result << desc
|
82
|
+
else
|
83
|
+
space = ' ' * desc_start
|
84
|
+
result << word_wrap(desc, desc_width).split("\n").join("\n#{space}")
|
85
|
+
end
|
86
|
+
end.join("\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
# @return [String]
|
90
|
+
#
|
91
|
+
def prettify_option_name(name)
|
92
|
+
name
|
57
93
|
end
|
58
94
|
|
59
95
|
# @return [String]
|
@@ -63,21 +99,28 @@ module CLAide
|
|
63
99
|
message = strip_heredoc(message)
|
64
100
|
message = message.split("\n").map { |line| " #{line}" }.join("\n")
|
65
101
|
args = " #{command.arguments}" if command.arguments
|
66
|
-
"
|
102
|
+
cmd = "$ #{command.full_command}#{args}"
|
103
|
+
" #{prettify_command_in_usage_description(cmd)}\n\n#{message}"
|
67
104
|
end
|
68
105
|
end
|
69
106
|
|
107
|
+
# @return [String]
|
108
|
+
#
|
109
|
+
def prettify_command_in_usage_description(command)
|
110
|
+
command
|
111
|
+
end
|
112
|
+
|
70
113
|
# @return [String]
|
71
114
|
#
|
72
115
|
def formatted_subcommand_summaries
|
73
|
-
subcommands = command.
|
116
|
+
subcommands = command.subcommands_for_command_lookup.reject do |subcommand|
|
74
117
|
subcommand.summary.nil?
|
75
118
|
end.sort_by(&:command)
|
76
119
|
unless subcommands.empty?
|
77
120
|
command_size = subcommands.map { |cmd| cmd.command.size }.max
|
78
121
|
subcommands.map do |subcommand|
|
79
122
|
subcommand_string = subcommand.command.ljust(command_size)
|
80
|
-
subcommand_string = subcommand_string
|
123
|
+
subcommand_string = prettify_subcommand_name(subcommand_string)
|
81
124
|
is_default = subcommand.command == command.default_subcommand
|
82
125
|
if is_default
|
83
126
|
bullet_point = '-'
|
@@ -89,6 +132,12 @@ module CLAide
|
|
89
132
|
end
|
90
133
|
end
|
91
134
|
|
135
|
+
# @return [String]
|
136
|
+
#
|
137
|
+
def prettify_subcommand_name(name)
|
138
|
+
ansi_output? ? name.green : name
|
139
|
+
end
|
140
|
+
|
92
141
|
private
|
93
142
|
|
94
143
|
# @!group Private helpers
|
@@ -105,6 +154,24 @@ module CLAide
|
|
105
154
|
end
|
106
155
|
end
|
107
156
|
|
157
|
+
# @return [String] Lifted straight from ActionView. Thanks guys!
|
158
|
+
#
|
159
|
+
def word_wrap(line, line_width)
|
160
|
+
line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
|
161
|
+
end
|
162
|
+
|
163
|
+
# @return [Fixnum] The width of the current terminal, unless being piped.
|
164
|
+
#
|
165
|
+
def terminal_width
|
166
|
+
@terminal_width ||= begin
|
167
|
+
if STDOUT.tty? && system('which tput > /dev/null 2>&1')
|
168
|
+
`tput cols`.to_i
|
169
|
+
else
|
170
|
+
0
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
108
175
|
end
|
109
176
|
end
|
110
177
|
end
|
data/lib/claide/help.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module CLAide
|
2
4
|
|
3
|
-
require 'claide/informative_error
|
5
|
+
require 'claide/informative_error'
|
4
6
|
|
5
7
|
# The exception class that is raised to indicate a help banner should be
|
6
8
|
# shown while running {Command.run}.
|
@@ -18,9 +20,18 @@ module CLAide
|
|
18
20
|
#
|
19
21
|
attr_reader :error_message
|
20
22
|
|
21
|
-
# @return [Bool] Whether the error message should
|
23
|
+
# @return [Bool] Whether the error message should use ANSI codes to
|
24
|
+
# prettify output.
|
22
25
|
#
|
23
|
-
attr_reader :
|
26
|
+
attr_reader :ansi_output
|
27
|
+
alias_method :ansi_output?, :ansi_output
|
28
|
+
|
29
|
+
def colorize
|
30
|
+
warn "[!] The use of `CLAide::Help#colorize` has been " \
|
31
|
+
"deprecated. Use `CLAide::Help#ansi_output` instead. " \
|
32
|
+
"(Called from: #{caller.first})"
|
33
|
+
ansi_output
|
34
|
+
end
|
24
35
|
alias_method :colorize?, :colorize
|
25
36
|
|
26
37
|
# @param [String] banner @see banner
|
@@ -30,10 +41,10 @@ module CLAide
|
|
30
41
|
# terminate the program with, will be set to `1`, otherwise a {Help}
|
31
42
|
# exception is treated as not being a real error and exits with `0`.
|
32
43
|
#
|
33
|
-
def initialize(banner, error_message = nil,
|
44
|
+
def initialize(banner, error_message = nil, ansi_output = false)
|
34
45
|
@banner = banner
|
35
46
|
@error_message = error_message
|
36
|
-
@
|
47
|
+
@ansi_output = ansi_output
|
37
48
|
@exit_status = @error_message.nil? ? 0 : 1
|
38
49
|
end
|
39
50
|
|
@@ -43,10 +54,16 @@ module CLAide
|
|
43
54
|
def formatted_error_message
|
44
55
|
if error_message
|
45
56
|
message = "[!] #{error_message}"
|
46
|
-
|
57
|
+
prettify_error_message(message)
|
47
58
|
end
|
48
59
|
end
|
49
60
|
|
61
|
+
# @return [String]
|
62
|
+
#
|
63
|
+
def prettify_error_message(message)
|
64
|
+
ansi_output? ? message.red : message
|
65
|
+
end
|
66
|
+
|
50
67
|
# @return [String] The optional error message, combined with the help
|
51
68
|
# banner of the command.
|
52
69
|
#
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: claide
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eloy Duran
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -19,14 +19,14 @@ executables: []
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- LICENSE
|
23
|
+
- README.markdown
|
24
|
+
- lib/claide.rb
|
22
25
|
- lib/claide/argv.rb
|
23
|
-
- lib/claide/command/banner.rb
|
24
26
|
- lib/claide/command.rb
|
27
|
+
- lib/claide/command/banner.rb
|
25
28
|
- lib/claide/help.rb
|
26
29
|
- lib/claide/informative_error.rb
|
27
|
-
- lib/claide.rb
|
28
|
-
- README.markdown
|
29
|
-
- LICENSE
|
30
30
|
homepage: https://github.com/CocoaPods/CLAide
|
31
31
|
licenses:
|
32
32
|
- MIT
|
@@ -37,17 +37,17 @@ require_paths:
|
|
37
37
|
- lib
|
38
38
|
required_ruby_version: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
49
|
rubyforge_project:
|
50
|
-
rubygems_version: 2.
|
50
|
+
rubygems_version: 2.2.2
|
51
51
|
signing_key:
|
52
52
|
specification_version: 3
|
53
53
|
summary: A small command-line interface framework.
|