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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15b5727f3d10b876b81b223b19fcac47a56cf293a66b34305b96517976b04613
4
- data.tar.gz: e047187d76098db98d240770dca013806512628ad1dcd54c613dc2627a7538d7
3
+ metadata.gz: b083e62e1f920ec5cbd706e7fda06f9ea7377de383b36a9778c5b191e63b9fc4
4
+ data.tar.gz: a6de7d045ea35b3fefd4cc2ca77e64cd4bb5bd29e39eace7cd9047c372e684a0
5
5
  SHA512:
6
- metadata.gz: e5e8f5850885c9bf9540b82b7a7866fdb9a317c32c94501e51cef85d65711fe5037ffc7924f68c206ff4654e2f998ae237e5fbb36b9495f9619aaba3d95418a4
7
- data.tar.gz: a6840ebf11d96c875e45a468ce492e2c748f20c3298121bc338b2f565d9b8f8c3dff6d278340d609f69ca98f8c0e8b52af3e40a4b93385d99dbc5fc4ae2c3c1c
6
+ metadata.gz: f37c40606f5ae5d2a0d05a13d0564e2f74d0a303a813bbf11c5f09eb37bdc53bbfd2541534a73c4fa399a8498428abff8fc3edf94f647447916a996af4168e99
7
+ data.tar.gz: 76a7afbab9913ff565e3d745f49ee532fd11cf84ad8624e858f309cdec856a6fe58b20bb9499ed882e9d1c3701620f2e8cb2cb0683db1128dbe2235e4b6b6f86
@@ -5,8 +5,8 @@ module Commander
5
5
  ##
6
6
  # Wrapper run command with error handling
7
7
  def run!(*args)
8
- Commander.traceable_error_handler(*args) do |new_args|
9
- run(*new_args)
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
- INTERRUPT_MSG = 'Received Interrupt!'
21
-
22
- def self.traceable_error_handler(*args)
23
- # Determines if there is a --trace flag before a --
24
- trace_index = args.index do |a|
25
- if a == '--trace'
26
- true
27
- elsif a == '--'
28
- break
29
- else
30
- false
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
- # Start the actual error handler
39
- error_handler(!!trace_index) do
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
- rescue Interrupt
44
- # Start Rescuing Interrupt Immediately
45
- $stderr.puts INTERRUPT_MSG
46
- exit 130
47
- end
48
-
49
- def self.error_handler(trace = false)
50
- yield if block_given?
51
- rescue StandardError, Interrupt => e
52
- $stderr.puts e.full_message if trace
53
-
54
- error_msg = e.message
55
- exit_code = e.respond_to?(:exit_code) ? e.exit_code.to_i : 1
56
- case e
57
- when InternalCallableError
58
- # See: https://shapeshed.com/unix-exit-codes/
59
- exit_code = 126
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
 
@@ -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 => e
95
- msg = "#{Paint[program(:name), '#2794d8']}: #{Paint[e.to_s, :red, :bright]}"
96
- new_error = e.exception(msg)
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 new_error
102
+ raise error
106
103
  end
107
104
 
108
105
  ##
@@ -1,3 +1,3 @@
1
1
  module Commander
2
- VERSION = '2.1.2'.freeze
2
+ VERSION = '2.2.0'.freeze
3
3
  end
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.1.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-05-22 00:00:00.000000000 Z
13
+ date: 2020-07-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: highline