gli 2.20.1 → 2.21.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: 5d3bbbc287b9e950b0e466400f14518010968c40a444cfa22486a51fa734134d
4
- data.tar.gz: d4414c2e6c9f981a7ccbad490fea52f0519ec45a6a7634f44d9ed4cfad3b1c24
3
+ metadata.gz: 0017e490227889383633bf3d4fc2f85783aa50cd86587fd35b704f4fa036d1c3
4
+ data.tar.gz: 96667382f9092e22abc794e6967d969cecea12339675e46d8a2990df0067810c
5
5
  SHA512:
6
- metadata.gz: b432b2e5d295bf7b3cf61683b1819353bca64158c5d07ed11135cd94ae8917dd352653f169f3306e1b26fcc9bce2199a5898d889f0819961b1260ee31fe5d710
7
- data.tar.gz: 60d93d19cfdc621cbfee7189140447f0fa074354153c6d840e67fff516a6bf06ebb9668d3c420b6e66e6103c4ccfd969742cf26760c68c6f091f660b8d40a6aa
6
+ metadata.gz: 7b76b5845f5beb5907d7c11355c5e02ba22521f124c0486f5d1d08ae75969338bc23434ac680da72306cd761cdaac986fb01c966e8eb14a664eb84db95164e82
7
+ data.tar.gz: 55f76b94f22cf271a93bc0e0916c1a500175fbaa5a45a01c74372042baba384da6660f5860946bf803c7db14c23712f51249ee03c6a1a2d9d52c3da05638eaeb
data/.circleci/config.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  version: 2.1
2
2
  orbs:
3
3
  # See https://circleci.com/developer/orbs/orb/circleci/ruby
4
- ruby: circleci/ruby@1.1.2
4
+ ruby: circleci/ruby@1.4.0
5
5
  jobs: # keyword
6
6
  test: # my name for the job
7
7
  parameters: # keyword
@@ -16,7 +16,7 @@ jobs: # keyword
16
16
  - run:
17
17
  command: "bin/setup"
18
18
  - run:
19
- command: "bin/ci"
19
+ command: "bin/ci none"
20
20
  workflows: # keyword
21
21
  all-rubies: # my name for the workflow
22
22
  jobs: # keyword
data/CONTRIBUTING.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Contributions are welcome as long as they are part of my vision for GLI (or can be treated as optional to the user). I am obsessive about backwards-compatibility, so you may need to default things to disable your features. Sorry, not ready to bump a major version any time soon.
2
2
 
3
3
  1. Fork my Repository
4
- 2. Create a branch off of gli-2 (**master is no longer the canonical branch**)
4
+ 2. Create a branch off of main
5
5
  3. Make your changes:
6
6
  * Please include tests and watch out for reek and roodi; i.e. keep your code clean
7
7
  * If you make changes to the gli executable or the scaffolding, please update the cucumber features
@@ -19,5 +19,3 @@ Contributions are welcome as long as they are part of my vision for GLI (or can
19
19
  * Use <code># :nodoc:</code> for methods that a _user_ of GLI should not call (but still please do document all methods)
20
20
  4. Make sure your branch will merge with my gli-2 branch (or just rebase your branch from my gli-2 branch)
21
21
  5. Create a pull request explaining your change
22
-
23
-
data/Rakefile CHANGED
@@ -106,5 +106,5 @@ end
106
106
  desc 'Publish rdoc on github pages and push to github'
107
107
  task :publish_rdoc => [:rdoc,:publish]
108
108
 
109
- task :default => [:test,:features]
109
+ task :default => ["test:unit", "test:integraton"]
110
110
 
@@ -15,6 +15,7 @@ module GLI
15
15
  switches.clear
16
16
  flags.clear
17
17
  @commands = nil
18
+ @command_missing_block = nil
18
19
  @commands_declaration_order = []
19
20
  @flags_declaration_order = []
20
21
  @switches_declaration_order = []
@@ -72,7 +73,8 @@ module GLI
72
73
  :default_command => @default_command,
73
74
  :autocomplete => autocomplete,
74
75
  :subcommand_option_handling_strategy => subcommand_option_handling_strategy,
75
- :argument_handling_strategy => argument_handling_strategy)
76
+ :argument_handling_strategy => argument_handling_strategy,
77
+ :command_missing_block => @command_missing_block)
76
78
 
77
79
  parsing_result = gli_option_parser.parse_options(args)
78
80
  parsing_result.convert_to_openstruct! if @use_openstruct
data/lib/gli/dsl.rb CHANGED
@@ -201,9 +201,14 @@ module GLI
201
201
  end
202
202
  clear_nexts
203
203
  @next_arguments = []
204
+ command
204
205
  end
205
206
  alias :c :command
206
207
 
208
+ def command_missing(&block)
209
+ @command_missing_block = block
210
+ end
211
+
207
212
  def flags_declaration_order # :nodoc:
208
213
  @flags_declaration_order ||= []
209
214
  end
@@ -16,7 +16,7 @@ module GLI
16
16
  command_finder = CommandFinder.new(commands,
17
17
  :default_command => (options[:default_command] || :help),
18
18
  :autocomplete => options[:autocomplete])
19
- @global_option_parser = GlobalOptionParser.new(OptionParserFactory.new(flags,switches,accepts),command_finder,flags)
19
+ @global_option_parser = GlobalOptionParser.new(OptionParserFactory.new(flags,switches,accepts),command_finder,flags, :command_missing_block => options[:command_missing_block])
20
20
  @accepts = accepts
21
21
  if options[:argument_handling_strategy] == :strict && options[:subcommand_option_handling_strategy] != :normal
22
22
  raise ArgumentError, "To use strict argument handling, you must enable normal subcommand_option_handling, e.g. subcommand_option_handling :normal"
@@ -36,10 +36,11 @@ module GLI
36
36
  private
37
37
 
38
38
  class GlobalOptionParser
39
- def initialize(option_parser_factory,command_finder,flags)
39
+ def initialize(option_parser_factory,command_finder,flags,options={})
40
40
  @option_parser_factory = option_parser_factory
41
41
  @command_finder = command_finder
42
42
  @flags = flags
43
+ @options = options
43
44
  end
44
45
 
45
46
  def parse!(parsing_result)
@@ -50,7 +51,21 @@ module GLI
50
51
  else
51
52
  parsing_result.arguments.shift
52
53
  end
53
- parsing_result.command = @command_finder.find_command(command_name)
54
+ parsing_result.command = begin
55
+ @command_finder.find_command(command_name)
56
+ rescue UnknownCommand => e
57
+ raise e unless @options[:command_missing_block]
58
+ command = @options[:command_missing_block].call(command_name.to_sym,parsing_result.global_options)
59
+ if command
60
+ unless command.is_a?(Command)
61
+ raise UnknownCommand.new("Expected the `command_missing` block to return a GLI::Command object, got a #{command.class.name} instead.")
62
+ end
63
+ else
64
+ raise e
65
+ end
66
+ command
67
+ end
68
+
54
69
  unless command_name == 'help'
55
70
  verify_required_options!(@flags, parsing_result.command, parsing_result.global_options)
56
71
  end
@@ -143,7 +158,7 @@ module GLI
143
158
  break
144
159
  rescue UnknownCommand
145
160
  arguments.unshift(next_command_name)
146
- # Although command finder could certainy know if it should use
161
+ # Although command finder could certainly know if it should use
147
162
  # the default command, it has no way to put the "unknown command"
148
163
  # back into the argument stack. UGH.
149
164
  unless command.get_default_command.nil?
data/lib/gli/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module GLI
2
2
  unless const_defined? :VERSION
3
- VERSION = '2.20.1'
3
+ VERSION = '2.21.0'
4
4
  end
5
5
  end
@@ -783,6 +783,36 @@ class GLITest < MiniTest::Test
783
783
  assert_equal %w(-f some_flag foo bar blah),argv
784
784
  end
785
785
 
786
+ def test_missing_command
787
+ @called = false
788
+ @app.command_missing do |command_name, global_options|
789
+ @app.command command_name do |c|
790
+ c.action do
791
+ @called = true
792
+ end
793
+ end
794
+ end
795
+
796
+ assert_equal 0, @app.run(['foobar']),"Expected exit status to be 0"
797
+ assert @called,"Expected missing command to be called"
798
+ end
799
+
800
+ def test_missing_command_not_handled
801
+ @app.command_missing do |command_name, global_options|
802
+ # do nothing, i.e. don't handle the command
803
+ end
804
+
805
+ assert_equal 64,@app.run(['foobar']),"Expected exit status to be 64"
806
+ end
807
+
808
+ def test_missing_command_returns_non_command_object
809
+ @app.command_missing do |command_name, global_options|
810
+ true
811
+ end
812
+
813
+ assert_equal 64,@app.run(['foobar']),"Expected exit status to be 64"
814
+ end
815
+
786
816
  private
787
817
 
788
818
  def do_test_flag_create(object)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.20.1
4
+ version: 2.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Copeland
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-27 00:00:00.000000000 Z
11
+ date: 2022-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake