gli 2.6.1 → 2.6.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.
@@ -175,6 +175,7 @@ Feature: The todo app has a nice user interface
175
175
  | help list |
176
176
  | list -h |
177
177
  | list --help |
178
+ | --help list |
178
179
 
179
180
 
180
181
  Scenario: Getting Help for a top level command of todo with no command options
@@ -61,7 +61,7 @@ module GLI
61
61
  begin
62
62
  override_defaults_based_on_config(parse_config)
63
63
 
64
- add_help_switch_if_needed(switches)
64
+ add_help_switch_if_needed(self)
65
65
 
66
66
  gli_option_parser = GLIOptionParser.new(commands,
67
67
  flags,
@@ -79,7 +79,7 @@ module GLI
79
79
  call_command(parsing_result)
80
80
  0
81
81
  else
82
- exit_now!(nil,65)
82
+ raise PreconditionFailed, "preconditions failed"
83
83
  end
84
84
  rescue Exception => ex
85
85
  if the_command.nil? && ex.respond_to?(:command_in_context)
@@ -231,15 +231,13 @@ module GLI
231
231
 
232
232
  end
233
233
 
234
- def add_help_switch_if_needed(switches)
235
- help_switch_exists = switches.values.find { |switch|
236
- (Array(switch.aliases) + [switch.name]).find { |an_alias|
237
- an_alias.to_s == 'help'
238
- }
234
+ def add_help_switch_if_needed(target)
235
+ help_switch_exists = target.switches.values.find { |switch|
236
+ switch.names_and_aliases.map(&:to_s).find { |an_alias| an_alias == 'help' }
239
237
  }
240
238
  unless help_switch_exists
241
- desc 'Show this message'
242
- switch :help, :negatable => false
239
+ target.desc 'Show this message'
240
+ target.switch :help, :negatable => false
243
241
  end
244
242
  end
245
243
 
@@ -11,6 +11,11 @@ module GLI
11
11
  def exit_code; 64; end
12
12
  end
13
13
 
14
+ class PreconditionFailed < StandardError
15
+ include StandardException
16
+ def exit_code; 65; end
17
+ end
18
+
14
19
  # Indicates the bad command line was an unknown command
15
20
  class UnknownCommand < BadCommandLine
16
21
  end
@@ -28,8 +28,12 @@ module GLI
28
28
 
29
29
  def parse!(parsing_result)
30
30
  parsing_result.arguments = GLIOptionBlockParser.new(@option_parser_factory,UnknownGlobalArgument).parse!(parsing_result.arguments)
31
- command_name = parsing_result.arguments.shift
32
31
  parsing_result.global_options = @option_parser_factory.options_hash_with_defaults_set!
32
+ command_name = if parsing_result.global_options[:help]
33
+ "help"
34
+ else
35
+ parsing_result.arguments.shift
36
+ end
33
37
  parsing_result.command = @command_finder.find_command(command_name)
34
38
  parsing_result
35
39
  end
@@ -1,5 +1,5 @@
1
1
  module GLI
2
2
  unless const_defined? :VERSION
3
- VERSION = '2.6.1'
3
+ VERSION = '2.6.2'
4
4
  end
5
5
  end
@@ -355,7 +355,7 @@ class TC_testCommand < Clean::Test::TestCase
355
355
  @app.pre { |*| false }
356
356
 
357
357
  assert_equal 65,@app.run(["bs"]) # BSD for "input data incorrect in some way"
358
- assert_equal '',@fake_stderr.to_s
358
+ assert_equal 'error: preconditions failed',@fake_stderr.to_s
359
359
  assert_equal '',@fake_stdout.to_s
360
360
  end
361
361
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.1
4
+ version: 2.6.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-26 00:00:00.000000000 Z
12
+ date: 2013-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake