commander-openflighthpc 2.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/commander/cli.rb +2 -2
- data/lib/commander/error_handler.rb +35 -45
- data/lib/commander/runner.rb +5 -8
- data/lib/commander/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b083e62e1f920ec5cbd706e7fda06f9ea7377de383b36a9778c5b191e63b9fc4
|
4
|
+
data.tar.gz: a6de7d045ea35b3fefd4cc2ca77e64cd4bb5bd29e39eace7cd9047c372e684a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f37c40606f5ae5d2a0d05a13d0564e2f74d0a303a813bbf11c5f09eb37bdc53bbfd2541534a73c4fa399a8498428abff8fc3edf94f647447916a996af4168e99
|
7
|
+
data.tar.gz: 76a7afbab9913ff565e3d745f49ee532fd11cf84ad8624e858f309cdec856a6fe58b20bb9499ed882e9d1c3701620f2e8cb2cb0683db1128dbe2235e4b6b6f86
|
data/lib/commander/cli.rb
CHANGED
@@ -5,8 +5,8 @@ module Commander
|
|
5
5
|
##
|
6
6
|
# Wrapper run command with error handling
|
7
7
|
def run!(*args)
|
8
|
-
Commander.
|
9
|
-
run(*
|
8
|
+
Commander::ErrorHandler.new(program(:name)).start do |handler|
|
9
|
+
run(*handler.parse_trace(*args))
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'paint'
|
2
|
+
|
1
3
|
module Commander
|
2
4
|
##
|
3
5
|
# Internal error class to delay rendering help text
|
@@ -17,56 +19,44 @@ module Commander
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
if a
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
ErrorHandler = Struct.new(:program_name, :trace) do
|
23
|
+
def parse_trace(*raw_args)
|
24
|
+
# Do not modify the original array
|
25
|
+
args = raw_args.dup
|
26
|
+
|
27
|
+
# Determines if there is a --trace flag before a --
|
28
|
+
trace_index = args.index do |a|
|
29
|
+
if a == '--trace'
|
30
|
+
self.trace = true
|
31
|
+
elsif a == '--'
|
32
|
+
break
|
33
|
+
else
|
34
|
+
false
|
35
|
+
end
|
31
36
|
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Removes the --trace flag if required
|
35
|
-
new_args = args.dup
|
36
|
-
new_args.delete_at(trace_index) if trace_index
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
yield(new_args) if block_given?
|
38
|
+
# Removes the --trace flag if required
|
39
|
+
args.tap { |a| a.delete_at(trace_index) if trace_index }
|
41
40
|
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
exit_code
|
60
|
-
$stderr.puts error_msg
|
61
|
-
e.call
|
62
|
-
when Interrupt
|
63
|
-
$stderr.puts INTERRUPT_MSG
|
64
|
-
# See: https://shapeshed.com/unix-exit-codes/
|
65
|
-
exit_code = 130
|
66
|
-
else
|
67
|
-
$stderr.puts error_msg
|
42
|
+
def start
|
43
|
+
yield(self) if block_given?
|
44
|
+
rescue => e
|
45
|
+
$stderr.puts e.full_message if trace
|
46
|
+
|
47
|
+
error_msg = "#{Paint[program_name, '#2794d8']}: #{Paint[e.to_s, :red, :bright]}"
|
48
|
+
exit_code = e.respond_to?(:exit_code) ? e.exit_code.to_i : 1
|
49
|
+
case e
|
50
|
+
when InternalCallableError
|
51
|
+
# See: https://shapeshed.com/unix-exit-codes/
|
52
|
+
exit_code = 126
|
53
|
+
$stderr.puts error_msg
|
54
|
+
e.call
|
55
|
+
else
|
56
|
+
$stderr.puts error_msg
|
57
|
+
end
|
58
|
+
exit(exit_code)
|
68
59
|
end
|
69
|
-
exit(exit_code)
|
70
60
|
end
|
71
61
|
end
|
72
62
|
|
data/lib/commander/runner.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'paint'
|
2
1
|
require 'ostruct'
|
3
2
|
|
4
3
|
module Commander
|
@@ -91,18 +90,16 @@ module Commander
|
|
91
90
|
# Return generic help
|
92
91
|
run_help_command('')
|
93
92
|
end
|
94
|
-
rescue =>
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
if INBUILT_ERRORS.include?(new_error.class)
|
99
|
-
new_error = InternalCallableError.new(e.message) do
|
93
|
+
rescue => original
|
94
|
+
error = original
|
95
|
+
if INBUILT_ERRORS.include?(error.class)
|
96
|
+
error = InternalCallableError.new(error.message) do
|
100
97
|
$stderr.puts "\nUsage:\n\n"
|
101
98
|
name = active_command? ? active_command.name : :error
|
102
99
|
run_help_command([name])
|
103
100
|
end
|
104
101
|
end
|
105
|
-
raise
|
102
|
+
raise error
|
106
103
|
end
|
107
104
|
|
108
105
|
##
|
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: 2.
|
4
|
+
version: 2.2.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: 2020-
|
13
|
+
date: 2020-07-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: highline
|