claide 0.6.1 → 0.7.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.
- checksums.yaml +4 -4
- data/lib/claide/ansi.rb +3 -3
- data/lib/claide/argument.rb +62 -0
- data/lib/claide/command/banner/prettifier.rb +9 -7
- data/lib/claide/command/banner.rb +12 -11
- data/lib/claide/command/options.rb +4 -5
- data/lib/claide/command/plugins_helper.rb +56 -50
- data/lib/claide/command/validation_helper.rb +24 -4
- data/lib/claide/command.rb +95 -32
- data/lib/claide/helper.rb +6 -4
- data/lib/claide.rb +2 -1
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa421ae80f05ff7766c67d15049c75363ea796ca
|
4
|
+
data.tar.gz: 6c85d3c205a7f365992cb83913663e923eaf89e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 125926a5f8beb325d3e5a8a8b834de3db972cf402d62dab2c7afcfba52dd8738f152c30dceb02ce41a42a5ed5715d135b49d155e0ecfd2c021a8f64c9dd3b5ab
|
7
|
+
data.tar.gz: 99bf6357be57b12289b94501bd708c558b4ac45c9ada4321f0927b4e9f087e39c971bdfbdf20ed7cb0530ae42522c245d8fc70f0a853a00bbc71cba995d6f90a
|
data/lib/claide/ansi.rb
CHANGED
@@ -43,7 +43,7 @@ module CLAide
|
|
43
43
|
:underline => 4,
|
44
44
|
:blink => 5,
|
45
45
|
:reverse => 7,
|
46
|
-
:hidden => 8
|
46
|
+
:hidden => 8,
|
47
47
|
}
|
48
48
|
|
49
49
|
# @return [Hash{Symbol => Fixnum}] The codes to disable a text attribute by
|
@@ -54,7 +54,7 @@ module CLAide
|
|
54
54
|
:underline => 24,
|
55
55
|
:blink => 25,
|
56
56
|
:reverse => 27,
|
57
|
-
:hidden => 28
|
57
|
+
:hidden => 28,
|
58
58
|
}
|
59
59
|
|
60
60
|
# Return [String] The escape sequence to reset the graphics.
|
@@ -71,7 +71,7 @@ module CLAide
|
|
71
71
|
:blue => 4,
|
72
72
|
:magenta => 5,
|
73
73
|
:cyan => 6,
|
74
|
-
:white => 7
|
74
|
+
:white => 7,
|
75
75
|
}
|
76
76
|
|
77
77
|
# Return [String] The escape sequence for the default foreground color.
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module CLAide
|
4
|
+
# This class is used to represent individual arguments to present to
|
5
|
+
# the command help banner
|
6
|
+
#
|
7
|
+
class Argument
|
8
|
+
# The string used for ellipsis / repeatable arguments in the banner
|
9
|
+
#
|
10
|
+
ELLIPSIS = '...'
|
11
|
+
|
12
|
+
# @return [Array<String>]
|
13
|
+
# List of alternate names for the parameters
|
14
|
+
attr_reader :names
|
15
|
+
|
16
|
+
# @return [Boolean]
|
17
|
+
# Indicates if the argument is required (not optional)
|
18
|
+
#
|
19
|
+
attr_accessor :required
|
20
|
+
alias_method :required?, :required
|
21
|
+
|
22
|
+
# @return [Boolean]
|
23
|
+
# Indicates if the argument is repeatable (= can appear multiple
|
24
|
+
# times in the command, which is indicated by '...' in the banner)
|
25
|
+
#
|
26
|
+
attr_accessor :repeatable
|
27
|
+
alias_method :repeatable?, :repeatable
|
28
|
+
|
29
|
+
# @param [String,Array<String>] names
|
30
|
+
# List of the names of each parameter alternatives.
|
31
|
+
# For convenience, if there is only one alternative for that
|
32
|
+
# parameter, we can use a String instead of a 1-item Array
|
33
|
+
#
|
34
|
+
# @param [Boolean] required
|
35
|
+
# true if the parameter is required, false if it is optional
|
36
|
+
#
|
37
|
+
# @param [Boolean] repeatable
|
38
|
+
# If true, the argument can appear multiple times in the command.
|
39
|
+
# In that case, an ellipsis will be appended after the argument
|
40
|
+
# in the help banner.
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
#
|
44
|
+
# # A required parameter that can be either a NAME or URL
|
45
|
+
# Argument.new(%(NAME URL), true)
|
46
|
+
#
|
47
|
+
def initialize(names, required, repeatable = false)
|
48
|
+
@names = Array(names)
|
49
|
+
@required = required
|
50
|
+
@repeatable = repeatable
|
51
|
+
end
|
52
|
+
|
53
|
+
# @return [Boolean] true on equality
|
54
|
+
#
|
55
|
+
# @param [Argument] other the Argument compared against
|
56
|
+
#
|
57
|
+
def ==(other)
|
58
|
+
other.is_a?(Argument) &&
|
59
|
+
names == other.names && required == other.required
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -18,11 +18,11 @@ module CLAide
|
|
18
18
|
components = [
|
19
19
|
[command, :green],
|
20
20
|
[subcommand, :green],
|
21
|
-
[argument, :magenta]
|
21
|
+
[argument, :magenta],
|
22
22
|
]
|
23
23
|
components.reduce('') do |memo, (string, ansi_key)|
|
24
|
-
memo
|
25
|
-
memo
|
24
|
+
next memo if !string || string.empty?
|
25
|
+
memo << ' ' << string.ansi.apply(ansi_key)
|
26
26
|
end.lstrip
|
27
27
|
end
|
28
28
|
|
@@ -30,12 +30,14 @@ module CLAide
|
|
30
30
|
#
|
31
31
|
def self.prettify_message(command, message)
|
32
32
|
message = message.dup
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
message.gsub!(/`#{name}`/, "`#{name}`".ansi.apply(ansi_key))
|
33
|
+
command.arguments.each do |arg|
|
34
|
+
arg.names.each do |name|
|
35
|
+
message.gsub!("`#{name.gsub(/\.{3}$/, '')}`", '\0'.ansi.magenta)
|
37
36
|
end
|
38
37
|
end
|
38
|
+
command.options.each do |(name, _description)|
|
39
|
+
message.gsub!("`#{name}`", '\0'.ansi.blue)
|
40
|
+
end
|
39
41
|
message
|
40
42
|
end
|
41
43
|
|
@@ -24,7 +24,7 @@ module CLAide
|
|
24
24
|
sections = [
|
25
25
|
['Usage', formatted_usage_description],
|
26
26
|
['Commands', formatted_subcommand_summaries],
|
27
|
-
['Options', formatted_options_description]
|
27
|
+
['Options', formatted_options_description],
|
28
28
|
]
|
29
29
|
banner = sections.map do |(title, body)|
|
30
30
|
[prettify_title("#{title}:"), body] unless body.empty?
|
@@ -65,8 +65,10 @@ module CLAide
|
|
65
65
|
# @return [String] The signature of the command.
|
66
66
|
#
|
67
67
|
def signature
|
68
|
-
|
69
|
-
|
68
|
+
full_command = command.full_command
|
69
|
+
sub_command = signature_sub_command
|
70
|
+
arguments = signature_arguments
|
71
|
+
result = prettify_signature(full_command, sub_command, arguments)
|
70
72
|
result.insert(0, '$ ')
|
71
73
|
result.insert(0, ' ' * (TEXT_INDENT - '$ '.size))
|
72
74
|
end
|
@@ -74,19 +76,18 @@ module CLAide
|
|
74
76
|
# @return [String] The subcommand indicator of the signature.
|
75
77
|
#
|
76
78
|
def signature_sub_command
|
77
|
-
if command.
|
78
|
-
|
79
|
-
end
|
80
|
-
''
|
79
|
+
return '[COMMAND]' if command.default_subcommand
|
80
|
+
return 'COMMAND' if command.subcommands.any?
|
81
81
|
end
|
82
82
|
|
83
83
|
# @return [String] The arguments of the signature.
|
84
84
|
#
|
85
85
|
def signature_arguments
|
86
|
-
command.arguments.
|
87
|
-
|
88
|
-
|
89
|
-
|
86
|
+
command.arguments.map do |arg|
|
87
|
+
names = arg.names.join('|')
|
88
|
+
names.concat(' ' + Argument::ELLIPSIS) if arg.repeatable?
|
89
|
+
arg.required? ? names : "[#{names}]"
|
90
|
+
end.join(' ')
|
90
91
|
end
|
91
92
|
|
92
93
|
# @return [String] The section describing the subcommands of the command.
|
@@ -10,7 +10,7 @@ module CLAide
|
|
10
10
|
#
|
11
11
|
DEFAULT_ROOT_OPTIONS = [
|
12
12
|
['--completion-script', 'Print the auto-completion script'],
|
13
|
-
['--version', 'Show the version of the tool']
|
13
|
+
['--version', 'Show the version of the tool'],
|
14
14
|
]
|
15
15
|
|
16
16
|
# @return [Array<Array<String, String>>] The default options implemented
|
@@ -19,7 +19,7 @@ module CLAide
|
|
19
19
|
DEFAULT_OPTIONS = [
|
20
20
|
['--verbose', 'Show more debugging information'],
|
21
21
|
['--no-ansi', 'Show output without ANSI codes'],
|
22
|
-
['--help', 'Show help banner of specified command']
|
22
|
+
['--help', 'Show help banner of specified command'],
|
23
23
|
]
|
24
24
|
|
25
25
|
# @return [Array<Array<String, String>>] The list of the default
|
@@ -67,9 +67,8 @@ module CLAide
|
|
67
67
|
def self.print_version(command)
|
68
68
|
puts command.class.version
|
69
69
|
if command.verbose?
|
70
|
-
|
71
|
-
|
72
|
-
puts PluginsHelper.plugin_info(path)
|
70
|
+
PluginsHelper.specifications.each do |spec|
|
71
|
+
puts "#{spec.name}: #{spec.version}"
|
73
72
|
end
|
74
73
|
end
|
75
74
|
end
|
@@ -2,72 +2,77 @@
|
|
2
2
|
|
3
3
|
module CLAide
|
4
4
|
class Command
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
# Handles plugin related logic logic for the `Command` class.
|
6
|
+
#
|
7
|
+
# Plugins are loaded the first time a command run and are identified by the
|
8
|
+
# prefix specified in the command class. Plugins must adopt the following
|
9
|
+
# conventions:
|
10
|
+
#
|
11
|
+
# - Support being loaded by a file located under the
|
12
|
+
# `lib/#{plugin_prefix}_plugin` relative path.
|
13
|
+
# - Be stored in a folder named after the plugin.
|
14
|
+
#
|
15
|
+
class PluginsHelper
|
16
|
+
class << self
|
17
|
+
# @return [Array<Pathname>] The list of the root directories of the
|
18
|
+
# loaded plugins.
|
19
|
+
#
|
20
|
+
attr_reader :plugin_paths
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Array<String>] Loads plugins via RubyGems looking for files
|
24
|
+
# named after the `PLUGIN_PREFIX_plugin` and returns the paths of
|
25
|
+
# the gems loaded successfully. Plugins are required safely.
|
8
26
|
#
|
9
27
|
def self.load_plugins(plugin_prefix)
|
28
|
+
return if plugin_paths
|
10
29
|
paths = PluginsHelper.plugin_load_paths(plugin_prefix)
|
11
|
-
|
30
|
+
plugin_paths = []
|
12
31
|
paths.each do |path|
|
13
|
-
if PluginsHelper.safe_require(path)
|
14
|
-
|
32
|
+
if PluginsHelper.safe_require(path.to_s)
|
33
|
+
plugin_paths << Pathname(path + './../../').cleanpath
|
15
34
|
end
|
16
35
|
end
|
17
|
-
|
36
|
+
|
37
|
+
@plugin_paths = plugin_paths
|
18
38
|
end
|
19
39
|
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# @param [String] path
|
23
|
-
# The load path of the plugin.
|
24
|
-
#
|
25
|
-
# @return [String] A string including the name and the version or a
|
26
|
-
# failure message.
|
40
|
+
# @return [Array<Specification>] The RubyGems specifications for the
|
41
|
+
# loaded plugins.
|
27
42
|
#
|
28
|
-
def self.
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
if spec
|
34
|
-
"#{spec.name}: #{spec.version}"
|
35
|
-
else
|
36
|
-
"[!] Unable to load a specification for `#{path}`"
|
37
|
-
end
|
43
|
+
def self.specifications
|
44
|
+
PluginsHelper.plugin_paths.map do |path|
|
45
|
+
specification(path)
|
46
|
+
end.compact
|
38
47
|
end
|
39
48
|
|
40
|
-
# @return [
|
41
|
-
#
|
49
|
+
# @return [Array<Specification>] The RubyGems specifications for the
|
50
|
+
# plugin with the given root path.
|
42
51
|
#
|
43
|
-
# @param [
|
44
|
-
# The
|
52
|
+
# @param [#to_s] path
|
53
|
+
# The root path of the plugin.
|
45
54
|
#
|
46
|
-
def self.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
55
|
+
def self.specification(path)
|
56
|
+
glob = Dir.glob("#{path}/*.gemspec")
|
57
|
+
spec = Gem::Specification.load(glob.first) if glob.count == 1
|
58
|
+
unless spec
|
59
|
+
warn '[!] Unable to load a specification for the plugin ' \
|
60
|
+
"`#{path}`".ansi.yellow
|
52
61
|
end
|
53
|
-
|
62
|
+
spec
|
54
63
|
end
|
55
64
|
|
56
|
-
# @return [String]
|
65
|
+
# @return [Array<String>] The list of the plugins whose root path appears
|
66
|
+
# in the backtrace of an exception.
|
57
67
|
#
|
58
|
-
# @param [
|
59
|
-
# The
|
68
|
+
# @param [Exception] exception
|
69
|
+
# The exception to analyze.
|
60
70
|
#
|
61
|
-
def self.
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
progress = progress + '/' + component
|
67
|
-
else
|
68
|
-
progress = component
|
69
|
-
end
|
70
|
-
end.reverse
|
71
|
+
def self.plugins_involved_in_exception(exception)
|
72
|
+
paths = plugin_paths.select do |plugin_path|
|
73
|
+
exception.backtrace.any? { |line| line.include?(plugin_path.to_s) }
|
74
|
+
end
|
75
|
+
paths.map { |path| path.to_s.split('/').last }
|
71
76
|
end
|
72
77
|
|
73
78
|
# Returns the paths of the files to require to load the available
|
@@ -77,10 +82,11 @@ module CLAide
|
|
77
82
|
#
|
78
83
|
def self.plugin_load_paths(plugin_prefix)
|
79
84
|
if plugin_prefix && !plugin_prefix.empty?
|
85
|
+
pattern = "#{plugin_prefix}_plugin"
|
80
86
|
if Gem.respond_to? :find_latest_files
|
81
|
-
Gem.find_latest_files(
|
87
|
+
Gem.find_latest_files(pattern)
|
82
88
|
else
|
83
|
-
Gem.find_files(
|
89
|
+
Gem.find_files(pattern)
|
84
90
|
end
|
85
91
|
else
|
86
92
|
[]
|
@@ -18,10 +18,7 @@ module CLAide
|
|
18
18
|
type = ARGV::Parser.argument_type(string)
|
19
19
|
list = suggestion_list(command_class, type)
|
20
20
|
suggestion = ValidationHelper.suggestion(string, list)
|
21
|
-
|
22
|
-
string_type = type == :arg ? 'command' : 'option'
|
23
|
-
"Unknown #{string_type}: `#{string}`\n" \
|
24
|
-
"Did you mean: #{pretty_suggestion}"
|
21
|
+
suggestion_message(suggestion, type, string)
|
25
22
|
end
|
26
23
|
|
27
24
|
# @return [Array<String>] The list of the valid arguments for a command
|
@@ -58,6 +55,29 @@ module CLAide
|
|
58
55
|
sorted.first
|
59
56
|
end
|
60
57
|
|
58
|
+
# @return [String] Returns a message including a suggestion for the given
|
59
|
+
# suggestion.
|
60
|
+
#
|
61
|
+
# @param [String, Nil] suggestion
|
62
|
+
# The suggestion.
|
63
|
+
#
|
64
|
+
# @param [Symbol] type
|
65
|
+
# The type of the suggestion.
|
66
|
+
#
|
67
|
+
# @param [String] string
|
68
|
+
# The unrecognized string.
|
69
|
+
#
|
70
|
+
def self.suggestion_message(suggestion, type, string)
|
71
|
+
string_type = type == :arg ? 'command' : 'option'
|
72
|
+
if suggestion
|
73
|
+
pretty_suggestion = prettify_validation_suggestion(suggestion, type)
|
74
|
+
"Unknown #{string_type}: `#{string}`\n" \
|
75
|
+
"Did you mean: #{pretty_suggestion}"
|
76
|
+
else
|
77
|
+
"Unknown #{string_type}: `#{string}`"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
61
81
|
# Prettifies the given validation suggestion according to the type.
|
62
82
|
#
|
63
83
|
# @param [String] suggestion
|
data/lib/claide/command.rb
CHANGED
@@ -89,44 +89,34 @@ module CLAide
|
|
89
89
|
#
|
90
90
|
attr_accessor :plugin_prefix
|
91
91
|
|
92
|
-
# @return [Array<
|
92
|
+
# @return [Array<Argument>]
|
93
93
|
# A list of arguments the command handles. This is shown
|
94
94
|
# in the usage section of the command’s help banner.
|
95
|
-
# Each
|
96
|
-
#
|
97
|
-
# - name is a String containing the argument
|
98
|
-
# - type is either :optional or :required
|
95
|
+
# Each Argument in the array represents an argument by its name
|
96
|
+
# (or list of alternatives) and whether it's required or optional
|
99
97
|
#
|
100
|
-
# @todo Remove deprecation
|
101
|
-
#
|
102
|
-
attr_accessor :arguments
|
103
98
|
def arguments
|
104
99
|
@arguments ||= []
|
105
100
|
end
|
106
101
|
|
107
|
-
# @param [Array<
|
108
|
-
# An array
|
109
|
-
# the
|
110
|
-
#
|
111
|
-
#
|
102
|
+
# @param [Array<Argument>] arguments
|
103
|
+
# An array listing the command arguments.
|
104
|
+
# Each Argument object describe the argument by its name
|
105
|
+
# (or list of alternatives) and whether it's required or optional
|
106
|
+
#
|
107
|
+
# @todo Remove deprecation
|
112
108
|
#
|
113
|
-
# rubocop:disable MethodLength
|
114
109
|
def arguments=(arguments)
|
115
110
|
if arguments.is_a?(Array)
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
@arguments = arguments.split(' ').map do |argument|
|
121
|
-
if argument.start_with?('[')
|
122
|
-
[argument.sub(/\[(.*)\]/, '\1'), :optional]
|
123
|
-
else
|
124
|
-
[argument, :required]
|
125
|
-
end
|
111
|
+
if arguments.empty? || arguments[0].is_a?(Argument)
|
112
|
+
@arguments = arguments
|
113
|
+
else
|
114
|
+
self.arguments_array = arguments
|
126
115
|
end
|
116
|
+
else
|
117
|
+
self.arguments_string = arguments
|
127
118
|
end
|
128
119
|
end
|
129
|
-
# rubocop:enable MethodLength
|
130
120
|
|
131
121
|
# @return [Boolean] The default value for {Command#ansi_output}. This
|
132
122
|
# defaults to `true` if `STDOUT` is connected to a TTY and
|
@@ -326,6 +316,11 @@ module CLAide
|
|
326
316
|
# @return [void]
|
327
317
|
#
|
328
318
|
def self.report_error(exception)
|
319
|
+
plugins = PluginsHelper.plugins_involved_in_exception(exception)
|
320
|
+
unless plugins.empty?
|
321
|
+
puts '[!] The exception involves the following plugins:' \
|
322
|
+
"\n - #{plugins.join("\n - ")}\n".ansi.yellow
|
323
|
+
end
|
329
324
|
raise exception
|
330
325
|
end
|
331
326
|
|
@@ -361,6 +356,19 @@ module CLAide
|
|
361
356
|
banner_class.new(self).formatted_banner
|
362
357
|
end
|
363
358
|
|
359
|
+
# @visibility private
|
360
|
+
#
|
361
|
+
# Print banner and exit
|
362
|
+
#
|
363
|
+
# @note Calling this method exits the current process.
|
364
|
+
#
|
365
|
+
# @return [void]
|
366
|
+
#
|
367
|
+
def self.banner!
|
368
|
+
puts banner
|
369
|
+
exit 0
|
370
|
+
end
|
371
|
+
|
364
372
|
#-------------------------------------------------------------------------#
|
365
373
|
|
366
374
|
# Set to `true` if the user specifies the `--verbose` option.
|
@@ -431,7 +439,7 @@ module CLAide
|
|
431
439
|
# @return [void]
|
432
440
|
#
|
433
441
|
def validate!
|
434
|
-
|
442
|
+
banner! if @argv.flag?('help')
|
435
443
|
unless @argv.empty?
|
436
444
|
help! ValidationHelper.argument_suggestion(@argv.remainder, self.class)
|
437
445
|
end
|
@@ -450,6 +458,21 @@ module CLAide
|
|
450
458
|
|
451
459
|
protected
|
452
460
|
|
461
|
+
# Returns the class of the invoked command
|
462
|
+
#
|
463
|
+
# @return [Command]
|
464
|
+
#
|
465
|
+
def invoked_command_class
|
466
|
+
if invoked_as_default?
|
467
|
+
self.class.superclass
|
468
|
+
else
|
469
|
+
self.class
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
# @param [String] error_message
|
474
|
+
# A custom optional error message
|
475
|
+
#
|
453
476
|
# @raise [Help]
|
454
477
|
#
|
455
478
|
# Signals CLAide that a help banner for this command should be shown,
|
@@ -458,14 +481,54 @@ module CLAide
|
|
458
481
|
# @return [void]
|
459
482
|
#
|
460
483
|
def help!(error_message = nil)
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
484
|
+
invoked_command_class.help!(error_message)
|
485
|
+
end
|
486
|
+
|
487
|
+
# Print banner and exit
|
488
|
+
#
|
489
|
+
# @note Calling this method exits the current process.
|
490
|
+
#
|
491
|
+
# @return [void]
|
492
|
+
#
|
493
|
+
def banner!
|
494
|
+
invoked_command_class.banner!
|
467
495
|
end
|
468
496
|
|
469
497
|
#-------------------------------------------------------------------------#
|
498
|
+
|
499
|
+
# Handle deprecated form of self.arguments as an
|
500
|
+
# Array<Array<(String, Symbol)>> like in:
|
501
|
+
#
|
502
|
+
# self.arguments = [ ['NAME', :required], ['QUERY', :optional] ]
|
503
|
+
#
|
504
|
+
# @todo Remove deprecated format support
|
505
|
+
#
|
506
|
+
def self.arguments_array=(arguments)
|
507
|
+
warn '[!] The signature of CLAide#arguments has changed. ' \
|
508
|
+
"Use CLAide::Argument (#{self}: `#{arguments}`)".ansi.yellow
|
509
|
+
@arguments = arguments.map do |(name_str, type)|
|
510
|
+
names = name_str.split('|')
|
511
|
+
required = (type == :required)
|
512
|
+
Argument.new(names, required)
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
# Handle deprecated form of self.arguments as a String, like in:
|
517
|
+
#
|
518
|
+
# self.arguments = 'NAME [QUERY]'
|
519
|
+
#
|
520
|
+
# @todo Remove deprecated format support
|
521
|
+
#
|
522
|
+
def self.arguments_string=(arguments)
|
523
|
+
warn '[!] The specification of arguments as a string has been' \
|
524
|
+
" deprecated #{self}: `#{arguments}`".ansi.yellow
|
525
|
+
@arguments = arguments.split(' ').map do |argument|
|
526
|
+
if argument.start_with?('[')
|
527
|
+
Argument.new(argument.sub(/\[(.*)\]/, '\1').split('|'), false)
|
528
|
+
else
|
529
|
+
Argument.new(argument.split('|'), true)
|
530
|
+
end
|
531
|
+
end
|
532
|
+
end
|
470
533
|
end
|
471
534
|
end
|
data/lib/claide/helper.rb
CHANGED
@@ -33,9 +33,10 @@ module CLAide
|
|
33
33
|
def self.format_markdown(string, indent = 0, max_width = 80)
|
34
34
|
paragraphs = Helper.strip_heredoc(string).split("\n\n")
|
35
35
|
paragraphs = paragraphs.map do |paragraph|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
if paragraph.start_with?(' ' * 4)
|
37
|
+
paragraph.gsub!(/\n/, "\n#{' ' * indent}")
|
38
|
+
else
|
39
|
+
paragraph = wrap_with_indent(paragraph, indent, max_width)
|
39
40
|
end
|
40
41
|
paragraph.insert(0, ' ' * indent).rstrip
|
41
42
|
end
|
@@ -62,9 +63,10 @@ module CLAide
|
|
62
63
|
width = [terminal_width, max_width].min
|
63
64
|
end
|
64
65
|
|
66
|
+
full_line = string.gsub("\n", ' ')
|
65
67
|
available_width = width - indent
|
66
68
|
space = ' ' * indent
|
67
|
-
word_wrap(
|
69
|
+
word_wrap(full_line, available_width).split("\n").join("\n#{space}")
|
68
70
|
end
|
69
71
|
|
70
72
|
# @return [String] Lifted straight from ActionView. Thanks guys!
|
data/lib/claide.rb
CHANGED
@@ -8,9 +8,10 @@ module CLAide
|
|
8
8
|
#
|
9
9
|
# CLAide’s version, following [semver](http://semver.org).
|
10
10
|
#
|
11
|
-
VERSION = '0.
|
11
|
+
VERSION = '0.7.0'
|
12
12
|
|
13
13
|
require 'claide/ansi'
|
14
|
+
require 'claide/argument'
|
14
15
|
require 'claide/argv'
|
15
16
|
require 'claide/command'
|
16
17
|
require 'claide/help'
|
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.7.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: 2014-
|
12
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -19,28 +19,29 @@ executables: []
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
-
- LICENSE
|
23
|
-
- README.markdown
|
24
|
-
- lib/claide.rb
|
25
|
-
- lib/claide/ansi.rb
|
26
22
|
- lib/claide/ansi/cursor.rb
|
27
23
|
- lib/claide/ansi/graphics.rb
|
28
24
|
- lib/claide/ansi/string_escaper.rb
|
29
|
-
- lib/claide/
|
25
|
+
- lib/claide/ansi.rb
|
26
|
+
- lib/claide/argument.rb
|
30
27
|
- lib/claide/argv/parser.rb
|
31
|
-
- lib/claide/
|
32
|
-
- lib/claide/command/banner.rb
|
28
|
+
- lib/claide/argv.rb
|
33
29
|
- lib/claide/command/banner/prettifier.rb
|
30
|
+
- lib/claide/command/banner.rb
|
34
31
|
- lib/claide/command/options.rb
|
35
32
|
- lib/claide/command/parser.rb
|
36
33
|
- lib/claide/command/plugins_helper.rb
|
37
|
-
- lib/claide/command/shell_completion_helper.rb
|
38
34
|
- lib/claide/command/shell_completion_helper/zsh_completion_generator.rb
|
35
|
+
- lib/claide/command/shell_completion_helper.rb
|
39
36
|
- lib/claide/command/validation_helper.rb
|
37
|
+
- lib/claide/command.rb
|
40
38
|
- lib/claide/help.rb
|
41
39
|
- lib/claide/helper.rb
|
42
40
|
- lib/claide/informative_error.rb
|
43
41
|
- lib/claide/mixins.rb
|
42
|
+
- lib/claide.rb
|
43
|
+
- README.markdown
|
44
|
+
- LICENSE
|
44
45
|
homepage: https://github.com/CocoaPods/CLAide
|
45
46
|
licenses:
|
46
47
|
- MIT
|
@@ -51,17 +52,17 @@ require_paths:
|
|
51
52
|
- lib
|
52
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
54
|
requirements:
|
54
|
-
- -
|
55
|
+
- - '>='
|
55
56
|
- !ruby/object:Gem::Version
|
56
57
|
version: '0'
|
57
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
|
-
- -
|
60
|
+
- - '>='
|
60
61
|
- !ruby/object:Gem::Version
|
61
62
|
version: '0'
|
62
63
|
requirements: []
|
63
64
|
rubyforge_project:
|
64
|
-
rubygems_version: 2.
|
65
|
+
rubygems_version: 2.0.14
|
65
66
|
signing_key:
|
66
67
|
specification_version: 3
|
67
68
|
summary: A small command-line interface framework.
|