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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 972e4ca346bd62603e922f6b214e726ad122ff327d75f7fd4db2c632e7b3137c
4
- data.tar.gz: 873b8b07429c76b48e82962c5bba7ef240a106d8a68bb31e78943f52447b99c6
3
+ metadata.gz: 9244a36a96cd23607e4b23d95d63cde73ccad177b578c6634399379532c3490d
4
+ data.tar.gz: e225760491eb6d17a4481500883ae97cf401adf4e65cc2a9f31d67b9b6efcd98
5
5
  SHA512:
6
- metadata.gz: 7982f4e8104109bcb4b74e647e3a362890f94b10e0b4d7f9fec6d1d0085a1e11dd0b177f1867eb1d5b7c660d964fa3eadacab4cd4addd34d7e9debd9961bc59a
7
- data.tar.gz: 07c5234d4d2dae8076a334916e1b89445e6697640e31da6ca655e3fd777de289d837e16c6a26acc91961ac497b7068803fdeaa0f721e840c42a7ab29f7f8af45
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.
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ['lib']
20
20
 
21
21
  s.add_runtime_dependency('highline', '~> 1.7.2')
22
+ s.add_runtime_dependency('paint', '~> 2.1.0')
22
23
 
23
24
  s.add_development_dependency('rspec', '~> 3.2')
24
25
  s.add_development_dependency('rake')
@@ -224,8 +224,9 @@ module Commander
224
224
  # Call the commands when_called block with _args_.
225
225
 
226
226
  def call(args = [])
227
- object = @when_called.shift
228
- meth = @when_called.shift || :call
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)
@@ -12,7 +12,7 @@ module Commander
12
12
  @runner = runner
13
13
  end
14
14
 
15
- def render
15
+ def render(opts = {})
16
16
  'Implement global help here'
17
17
  end
18
18
 
@@ -5,7 +5,7 @@
5
5
  <% else -%>
6
6
  <%= $terminal.color "SYNOPSIS", :bold %>:
7
7
 
8
- <%= @syntax -%>
8
+ <%= syntax -%>
9
9
 
10
10
  <% end -%>
11
11
 
@@ -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 %>
@@ -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 = nil
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 = 'commander help [command]'
347
+ c.syntax = "#{program(:name)} help [command]"
328
348
  c.description = 'Display global or [command] help documentation'
329
- c.example 'Display global help', 'command help'
330
- c.example "Display help for 'foo'", 'command help 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?
@@ -1,3 +1,3 @@
1
1
  module Commander
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.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: 1.0.0
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-03 00:00:00.000000000 Z
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