commander-openflighthpc 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c0a592cbb12504621312f36cdddf097c323c86a950e3f7d7c37a4562c4abbf1
4
- data.tar.gz: 649c690cdc63d4a0d1ce417c25c99200be22f801b413cf0ec845fcb56c556c52
3
+ metadata.gz: a40df29e6a019c3ff4bac1776e2752ceefd52ac7cf79f5e6d5d99ec32266c59b
4
+ data.tar.gz: 0fb111ee4776fd2fbcb359781e740f30572b7b0f6fb9474ddc014b11aa6c8da9
5
5
  SHA512:
6
- metadata.gz: fcb2dbdcf5e576bcdca50f36630112abb7fc0ca41d6571a24ae8712356f47c776bf0da0fda254c741d59e980b08d406e6bdd634d2a0bec131741237abada85de
7
- data.tar.gz: 379386f9349b2db8d3745133101fef5971cc84e2013567fb439ec01cb3ceabe17150fc219e082a9207d499254b4ff29ebab0b33e90a3b85ad2aa200430643dc0
6
+ metadata.gz: 27a69ae0244b52ddd67288b77a54cda2b0e54bc115c2212960fed7761d7aefe75fc86fb83114b328283c136aab097ae8cfa28f8be061d68891ed1900b87ff4d9
7
+ data.tar.gz: 87a25ff68ff7c522989e4c67002b6903433af6ace6a12779d23855f1be4e7d2b5257f33bd452ac708a439344f83c51ba911014b117dac90f01bfd144c8bd8714
@@ -9,6 +9,8 @@ OptionParser.prepend Commander::Patches::ImplicitShortTags
9
9
  OptionParser.prepend Commander::Patches::DecimalInteger
10
10
 
11
11
  module Commander
12
+ class SubCommandGroupError < StandardError; end
13
+
12
14
  class Command
13
15
  prepend Patches::ValidateInputs
14
16
 
@@ -159,7 +161,7 @@ module Commander
159
161
  alias action when_called
160
162
 
161
163
  ##
162
- # Handles displaying subcommand help. By default it will set the action to
164
+ # Handles displaying subcommand help. By default it will set the action to
163
165
  # display the subcommand if the action hasn't already been set
164
166
 
165
167
  def sub_command_group?
@@ -168,11 +170,7 @@ module Commander
168
170
 
169
171
  def sub_command_group=(value)
170
172
  @sub_command_group = value
171
- if @when_called.empty?
172
- self.action {
173
- exec("#{$0} #{ARGV.join(" ")} --help")
174
- }
175
- end
173
+ self.action { raise SubCommandGroupError } if value
176
174
  end
177
175
 
178
176
  def configure_sub_command(runner)
@@ -27,7 +27,10 @@ module Commander
27
27
 
28
28
  def assert_correct_number_of_args!(args)
29
29
  return if primary_command_word == 'help'
30
- if too_many_args?(args)
30
+ too_many = too_many_args?(args)
31
+ if too_many && sub_command_group?
32
+ raise CommandUsageError, "unrecognised command. Please select from the following:"
33
+ elsif too_many
31
34
  raise CommandUsageError, "excess arguments for command '#{primary_command_word}'"
32
35
  elsif too_few_args?(args)
33
36
  raise CommandUsageError, "insufficient arguments for command '#{primary_command_word}'"
@@ -3,20 +3,37 @@ require 'paint'
3
3
  module Commander
4
4
  class Runner
5
5
  DEFAULT_ERROR_HANDLER = lambda do |runner, e|
6
- $stderr.puts "#{Paint[runner.program(:name), '#2794d8']}: #{Paint[e.to_s, :red, :bright]}"
6
+ error_msg = "#{Paint[runner.program(:name), '#2794d8']}: #{Paint[e.to_s, :red, :bright]}"
7
7
  case e
8
8
  when OptionParser::InvalidOption,
9
9
  Commander::Runner::InvalidCommandError,
10
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])
11
+ # Display the error message for a specific command. Most likely due to
12
+ # invalid command syntax
13
+ if cmd = runner.active_command
14
+ $stderr.puts error_msg
15
+ $stderr.puts "\nUsage:\n\n"
16
+ runner.command('help').run(cmd.name)
17
+ # Display the main app help text when called without `--help`
18
+ elsif runner.args_without_command_name.empty?
19
+ $stderr.puts "Usage:\n\n"
20
+ runner.command('help').run(:error)
21
+ # Display the main app help text when called with arguments. Mostly
22
+ # likely an invalid syntax error
17
23
  else
18
- runner.command("help").run(:error)
24
+ $stderr.puts error_msg
25
+ $stderr.puts "\nUsage:\n\n"
26
+ runner.command('help').run(:error)
19
27
  end
28
+ # Display the help text for sub command groups when called without `--help`
29
+ when SubCommandGroupError
30
+ if cmd = runner.active_command
31
+ $stderr.puts "Usage:\n\n"
32
+ runner.command('help').run(cmd.name)
33
+ end
34
+ # Catch all error message for all other issues
35
+ else
36
+ $stderr.puts error_msg
20
37
  end
21
38
  exit(1)
22
39
  end
@@ -1,3 +1,3 @@
1
1
  module Commander
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.1.2'.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.1.1
4
+ version: 1.1.2
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-09-13 00:00:00.000000000 Z
13
+ date: 2019-09-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: highline