commander-openflighthpc 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/commander-openflighthpc.gemspec +1 -0
- data/lib/commander/command.rb +3 -2
- data/lib/commander/help_formatters/base.rb +1 -1
- data/lib/commander/help_formatters/terminal/command_help.erb +1 -1
- data/lib/commander/help_formatters/terminal/help.erb +10 -0
- data/lib/commander/runner.rb +34 -10
- data/lib/commander/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9244a36a96cd23607e4b23d95d63cde73ccad177b578c6634399379532c3490d
|
4
|
+
data.tar.gz: e225760491eb6d17a4481500883ae97cf401adf4e65cc2a9f31d67b9b6efcd98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b526cf9a75f0841eec29365ea8ebec7d256cc89801558e16e68c122149f0febec34b5419ab932551906c1422a8787c72ea5ca7faf9737c9bb523eefce7881026
|
7
|
+
data.tar.gz: ed26d596f553496191a3f9235cec46db82ba46143d5151ef4508812b4fdb9db7b560ef76608762d022f2b9ec110cfe9fd1e32aad1aeaf5efbda504f16ea4c3ff
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 1.1.0 / 2019-04-10
|
2
|
+
|
3
|
+
* Added banner handling.
|
4
|
+
* Added default error handling.
|
5
|
+
* Fixed help text for `help` command to use program name.
|
6
|
+
* Fixed bug in command calling that prevented commands being called twice.
|
7
|
+
|
1
8
|
# 1.0.0 / 2019-04-03
|
2
9
|
|
3
10
|
* Reset version numbering for this fork.
|
data/lib/commander/command.rb
CHANGED
@@ -224,8 +224,9 @@ module Commander
|
|
224
224
|
# Call the commands when_called block with _args_.
|
225
225
|
|
226
226
|
def call(args = [])
|
227
|
-
|
228
|
-
|
227
|
+
callee = @when_called.dup
|
228
|
+
object = callee.shift
|
229
|
+
meth = callee.shift || :call
|
229
230
|
options = proxy_option_struct
|
230
231
|
case object
|
231
232
|
when Proc then object.call(args, options)
|
@@ -1,3 +1,13 @@
|
|
1
|
+
<%=
|
2
|
+
if !program(:nobanner)
|
3
|
+
begin
|
4
|
+
require 'openflight/banner'
|
5
|
+
OpenFlight::Banner.render(title: program(:application), version: program(:version))
|
6
|
+
rescue LoadError
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
end
|
10
|
+
-%>
|
1
11
|
<%= $terminal.color "NAME", :bold %>:
|
2
12
|
|
3
13
|
<%= program :name %>
|
data/lib/commander/runner.rb
CHANGED
@@ -1,9 +1,29 @@
|
|
1
|
+
require 'paint'
|
2
|
+
|
1
3
|
module Commander
|
2
4
|
class Runner
|
5
|
+
DEFAULT_ERROR_HANDLER = lambda do |runner, e|
|
6
|
+
$stderr.puts "#{Paint[runner.program(:name), '#2794d8']}: #{Paint[e.to_s, :red, :bright]}"
|
7
|
+
case e
|
8
|
+
when OptionParser::InvalidOption,
|
9
|
+
Commander::Runner::InvalidCommandError,
|
10
|
+
Commander::Patches::CommandUsageError
|
11
|
+
$stderr.puts "\nUsage:\n\n"
|
12
|
+
args = ARGV.reject{|o| o[0] == '-'}
|
13
|
+
if runner.command(topic = args[0..1].join(" "))
|
14
|
+
runner.command("help").run(topic)
|
15
|
+
elsif runner.command(args[0])
|
16
|
+
runner.command("help").run(args[0])
|
17
|
+
else
|
18
|
+
runner.command("help").run(:error)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
exit(1)
|
22
|
+
end
|
23
|
+
|
3
24
|
#--
|
4
25
|
# Exceptions
|
5
26
|
#++
|
6
|
-
|
7
27
|
class CommandError < StandardError; end
|
8
28
|
class InvalidCommandError < CommandError; end
|
9
29
|
|
@@ -33,7 +53,7 @@ module Commander
|
|
33
53
|
@always_trace = false
|
34
54
|
@never_trace = false
|
35
55
|
@silent_trace = false
|
36
|
-
@error_handler =
|
56
|
+
@error_handler = DEFAULT_ERROR_HANDLER
|
37
57
|
create_default_commands
|
38
58
|
end
|
39
59
|
|
@@ -70,16 +90,16 @@ module Commander
|
|
70
90
|
begin
|
71
91
|
run_active_command
|
72
92
|
rescue InvalidCommandError => e
|
73
|
-
error_handler&.call(e) ||
|
93
|
+
error_handler&.call(self, e) ||
|
74
94
|
abort("#{e}. Use --help for more information")
|
75
95
|
rescue \
|
76
96
|
OptionParser::InvalidOption,
|
77
97
|
OptionParser::InvalidArgument,
|
78
98
|
OptionParser::MissingArgument => e
|
79
|
-
error_handler&.call(e) ||
|
99
|
+
error_handler&.call(self, e) ||
|
80
100
|
abort(e.to_s)
|
81
101
|
rescue => e
|
82
|
-
error_handler&.call(e) ||
|
102
|
+
error_handler&.call(self, e) ||
|
83
103
|
if @never_trace || @silent_trace
|
84
104
|
abort("error: #{e}.")
|
85
105
|
else
|
@@ -324,23 +344,27 @@ module Commander
|
|
324
344
|
|
325
345
|
def create_default_commands
|
326
346
|
command :help do |c|
|
327
|
-
c.syntax =
|
347
|
+
c.syntax = "#{program(:name)} help [command]"
|
328
348
|
c.description = 'Display global or [command] help documentation'
|
329
|
-
c.example 'Display global help',
|
330
|
-
c.example "Display help for 'foo'",
|
349
|
+
c.example 'Display global help', "#{program(:name)} help"
|
350
|
+
c.example "Display help for 'foo'", "#{program(:name)} help foo"
|
331
351
|
c.when_called do |args, _options|
|
332
352
|
UI.enable_paging if program(:help_paging)
|
333
353
|
@help_commands = @commands.dup
|
334
|
-
if args.empty?
|
354
|
+
if args.empty? || args[0] == :error
|
335
355
|
@help_options = @options.reject {|o| o[:switches].first == '--trace'}
|
336
356
|
@help_commands.reject! { |k, v| !!v.hidden }
|
357
|
+
old_wrap = $terminal.wrap_at
|
358
|
+
$terminal.wrap_at = nil
|
359
|
+
program(:nobanner, true) if args[0] == :error
|
337
360
|
say help_formatter.render
|
361
|
+
$terminal.wrap_at = old_wrap
|
338
362
|
else
|
339
363
|
command = command args.join(' ')
|
340
364
|
begin
|
341
365
|
require_valid_command command
|
342
366
|
rescue InvalidCommandError => e
|
343
|
-
error_handler&.call(e) ||
|
367
|
+
error_handler&.call(self, e) ||
|
344
368
|
abort("#{e}. Use --help for more information")
|
345
369
|
end
|
346
370
|
if command.sub_command_group?
|
data/lib/commander/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commander-openflighthpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alces Flight Ltd
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-04-
|
13
|
+
date: 2019-04-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: highline
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: 1.7.2
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: paint
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.1.0
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.1.0
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
44
|
name: rspec
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|