gli 2.21.5 → 2.22.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: 4090c5ae7772cf0833abb4eda596a2eb558577de6493a1389e90e68327f41093
4
- data.tar.gz: 8f18bf74f7ac11bf544ac28be9c326355199a138364b7189a10537c7eb2903f4
3
+ metadata.gz: e2423619abd7f36b8c610382c006ed96685d8cc7df37d85b69267a64287124de
4
+ data.tar.gz: f4bcf12c882dd944264b40202abc82a5f0e5c649f3f03e3934b8608cdc10e8c2
5
5
  SHA512:
6
- metadata.gz: '02638fe45837c6e17d83d8e1afaf3a90e94da181419b1dfc6f53db9487a90566ff281a2e9adc4155bd4baa379f5f43f379a716e788330e12f828ad2d9a233f99'
7
- data.tar.gz: fbd6c9281eaf31a203cf5f6331ce21f4241eeb6b7e8cfafc5c3c4d63e81455a60246d76aa411ec4c3ffee3137c48921c569b819f6e0b7cc0e95225c5cdf18a1f
6
+ metadata.gz: ee3166846a6da41489fea74cdda3e08a85982e00b480090f371606768f36086ca324c732e83704421b99bc7e474e5e5ae140d79d05f7c552525a9cb897717130
7
+ data.tar.gz: b09cf190a438d021f565adbaeebfc90d74aa110f5fc436a0fd59485882d096246ec5d11b1fbd55df3a0afa3a6a80a494bc0ead1d43c6795c4cfce8cf983b552b
@@ -127,7 +127,7 @@ module GLI
127
127
  end
128
128
 
129
129
  # Executes the command
130
- def execute(global_options,options,arguments)
130
+ def execute(global_options,options,arguments)
131
131
  get_action(arguments).call(global_options,options,arguments)
132
132
  end
133
133
 
@@ -31,27 +31,19 @@ module GLI
31
31
  SYNOPSIS
32
32
  <% synopses.each do |s| %>
33
33
  <%= s %>
34
- <% end %>
35
- <% unless @command.long_description.nil? %>
34
+ <% end %><% unless @command.long_description.nil? %>
36
35
 
37
36
  DESCRIPTION
38
37
  <%= wrapper.wrap(@command.long_description) %>
39
- <% end %>
40
- <% if options_description.strip.length != 0 %>
41
-
38
+ <% end %><% if options_description.strip.length != 0 %>
42
39
  COMMAND OPTIONS
43
40
  <%= options_description %>
44
- <% end %>
45
- <% unless @command.commands.empty? %>
46
-
41
+ <% end %><% unless @command.commands.empty? %>
47
42
  COMMANDS
48
43
  <%= commands_description %>
49
- <% end %>
50
- <% unless @command.examples.empty? %>
51
-
44
+ <% end %><% unless @command.examples.empty? %>
52
45
  <%= @command.examples.size == 1 ? 'EXAMPLE' : 'EXAMPLES' %>
53
46
 
54
-
55
47
  <%= command_examples %>
56
48
  <% end %>))
57
49
 
@@ -44,11 +44,9 @@ SYNOPSIS
44
44
  VERSION
45
45
  <%= @app.version_string %>
46
46
 
47
- <% end %>
48
- <% unless global_flags_and_switches.empty? %>
47
+ <% end %><% unless global_flags_and_switches.empty? %>
49
48
  GLOBAL OPTIONS
50
49
  <%= global_option_descriptions %>
51
-
52
50
  <% end %>
53
51
  COMMANDS
54
52
  <%= commands %>))
@@ -59,17 +59,42 @@ module GLI
59
59
  end
60
60
  end
61
61
 
62
- class MissingRequiredArgumentsException < BadCommandLine
62
+ class BadCommandOptionsOrArguments < BadCommandLine
63
63
  # The command for which the argument was unknown
64
64
  attr_reader :command_in_context
65
- # +message+:: the error message to show the user
66
- # +command+:: the command we were using to parse command-specific options
67
65
  def initialize(message,command)
68
66
  super(message)
69
67
  @command_in_context = command
70
68
  end
71
69
  end
72
70
 
71
+ class MissingRequiredArgumentsException < BadCommandOptionsOrArguments
72
+ attr_reader :num_arguments_received, :range_arguments_accepted
73
+ def initialize(command,num_arguments_received,range_arguments_accepted)
74
+
75
+ @num_arguments_received = num_arguments_received
76
+ @range_arguments_accepted = range_arguments_accepted
77
+
78
+ message = if @num_arguments_received < @range_arguments_accepted.min
79
+ "#{command.name} expected at least #{@range_arguments_accepted.min} arguments, but was given only #{@num_arguments_received}"
80
+ elsif @range_arguments_accepted.min == 0
81
+ "#{command.name} expected no arguments, but received #{@num_arguments_received}"
82
+ else
83
+ "#{command.name} expected only #{@range_arguments_accepted.max} arguments, but received #{@num_arguments_received}"
84
+ end
85
+ super(message,command)
86
+ end
87
+
88
+ end
89
+
90
+ class MissingRequiredOptionsException < BadCommandOptionsOrArguments
91
+ def initialize(command,missing_required_options)
92
+ message = "#{command.name} requires these options: "
93
+ required_options = missing_required_options.sort.map(&:name).join(", ")
94
+ super(message + required_options,command)
95
+ end
96
+ end
97
+
73
98
  # Indicates the bad command line was an unknown command argument
74
99
  class UnknownCommandArgument < CommandException
75
100
  end
@@ -98,12 +98,13 @@ module GLI
98
98
  end
99
99
 
100
100
  # Now validate the number of arguments
101
- if arguments.size < min_number_of_arguments
102
- raise MissingRequiredArgumentsException.new("Not enough arguments for command", command)
103
- end
104
- if arguments.size > max_number_of_arguments
105
- raise MissingRequiredArgumentsException.new("Too many arguments for command", command)
101
+ num_arguments_range = min_number_of_arguments..max_number_of_arguments
102
+ if !num_arguments_range.cover?(arguments.size)
103
+ raise MissingRequiredArgumentsException.new(command,arguments.size,num_arguments_range)
106
104
  end
105
+ #if arguments.size > max_number_of_arguments
106
+ # raise TooManyArgumentsException.new(command,arguments.size,max_number_of_arguments)
107
+ #end
107
108
  end
108
109
 
109
110
  def verify_required_options!(flags, command, options)
@@ -114,10 +115,7 @@ module GLI
114
115
  ( options[option.name].kind_of?(Array) && options[option.name].empty? )
115
116
  }
116
117
  unless missing_required_options.empty?
117
- missing_required_options.sort!
118
- raise MissingRequiredArgumentsException.new(missing_required_options.map { |option|
119
- "#{option.name} is required"
120
- }.join(', '), command)
118
+ raise MissingRequiredOptionsException.new(command,missing_required_options)
121
119
  end
122
120
  end
123
121
  end
data/lib/gli/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module GLI
2
2
  unless const_defined? :VERSION
3
- VERSION = '2.21.5'
3
+ VERSION = '2.22.0'
4
4
  end
5
5
  end
@@ -29,7 +29,7 @@ class GLIPoweredAppTest < Minitest::Test
29
29
 
30
30
  def test_missing_args_exits_nonzero
31
31
  out, err, status = run_app("list", expect_failure: true, return_err_and_status: true)
32
- assert_match /required_flag is required, required_flag2 is required/,err
32
+ assert_match /list requires these options: required_flag, required_flag2/,err
33
33
  assert_equal 64, status.exitstatus
34
34
  assert_match /COMMAND OPTIONS/, out
35
35
  end
@@ -71,9 +71,8 @@ class GLITest < Minitest::Test
71
71
  end
72
72
  end
73
73
  assert_equal 64, @app.run(['foo']), "Expected exit status to be 64"
74
- assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
75
- assert @fake_stderr.contained?(/other_flag is required/), @fake_stderr.strings.inspect
76
- assert @fake_stderr.contained?(/flag is required, other_flag is required/), @fake_stderr.strings.inspect
74
+ assert @fake_stderr.contained?(/requires these options.*flag/), @fake_stderr.strings.inspect
75
+ assert @fake_stderr.contained?(/requires these options.*other_flag/), @fake_stderr.strings.inspect
77
76
  assert !@called
78
77
 
79
78
  assert_equal 0, @app.run(['foo','--flag=bar','--other_flag=blah']), "Expected exit status to be 0 #{@fake_stderr.strings.join(',')}"
@@ -91,8 +90,7 @@ class GLITest < Minitest::Test
91
90
  end
92
91
  end
93
92
  assert_equal 64, @app.run(['foo']), "Expected exit status to be 64"
94
- assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
95
- assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
93
+ assert @fake_stderr.contained?(/requires these options.*flag/), @fake_stderr.strings.inspect
96
94
  assert !@called
97
95
 
98
96
  assert_equal 0, @app.run(['foo','--flag=bar']), "Expected exit status to be 0 #{@fake_stderr.strings.join(',')}"
@@ -111,9 +109,8 @@ class GLITest < Minitest::Test
111
109
  end
112
110
  end
113
111
  assert_equal 64, @app.run(['foo']), "Expected exit status to be 64"
114
- assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
115
- assert @fake_stderr.contained?(/other_flag is required/), @fake_stderr.strings.inspect
116
- assert @fake_stderr.contained?(/flag is required, other_flag is required/), @fake_stderr.strings.inspect
112
+ assert @fake_stderr.contained?(/requires these options.*flag/), @fake_stderr.strings.inspect
113
+ assert @fake_stderr.contained?(/requires these options.*other_flag/), @fake_stderr.strings.inspect
117
114
  assert !@called
118
115
 
119
116
  assert_equal 0, @app.run(['--flag=bar','--other_flag=blah','foo']), "Expected exit status to be 0 #{@fake_stderr.strings.join(',')}"
@@ -131,8 +128,7 @@ class GLITest < Minitest::Test
131
128
  end
132
129
  end
133
130
  assert_equal 64, @app.run(['foo']), "Expected exit status to be 64"
134
- assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
135
- assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
131
+ assert @fake_stderr.contained?(/requires these options.*flag/), @fake_stderr.strings.inspect
136
132
  assert !@called
137
133
 
138
134
  assert_equal 0, @app.run(['--flag=bar','foo']), "Expected exit status to be 0 #{@fake_stderr.strings.join(',')}"
@@ -78,8 +78,8 @@ class SubcommandParsingTest < Minitest::Test
78
78
  setup_app_with_subcommand_storing_results :normal, false, :strict
79
79
  @app.run(%w(-f global command -f flag -s subcomm -f subflag))
80
80
  with_clue {
81
+ assert @fake_stderr.contained?(/expected no arguments, but received 3/)
81
82
  assert_equal nil,@results[:command_name]
82
- assert @fake_stderr.contained?(/error: Too many arguments for command/)
83
83
  }
84
84
  end
85
85
 
@@ -123,8 +123,8 @@ class SubcommandParsingTest < Minitest::Test
123
123
  with_clue {
124
124
  assert_equal number_generated, @results[:number_of_args_give_to_action]
125
125
  assert_equal 0, @exit_code
126
- assert !@fake_stderr.contained?(/Not enough arguments for command/)
127
- assert !@fake_stderr.contained?(/Too many arguments for command/)
126
+ assert !@fake_stderr.contained?(/expected at least/)
127
+ assert !@fake_stderr.contained?(/expected only/)
128
128
  }
129
129
  end
130
130
  end
@@ -144,11 +144,15 @@ class SubcommandParsingTest < Minitest::Test
144
144
  if status == :not_enough then
145
145
  assert_nil @results[:number_of_args_give_to_action]
146
146
  assert_equal 64, @exit_code
147
- assert @fake_stderr.contained?(/Not enough arguments for command/)
147
+ assert @fake_stderr.contained?(/expected at least #{number_required} arguments, but was given only #{number_generated}/)
148
148
  elsif status == :too_many then
149
149
  assert_nil @results[:number_of_args_give_to_action]
150
150
  assert_equal 64, @exit_code
151
- assert @fake_stderr.contained?(/Too many arguments for command/)
151
+ if number_required == 0
152
+ assert @fake_stderr.contained?(/expected no arguments, but received #{number_generated}/)
153
+ else
154
+ assert @fake_stderr.contained?(/expected only #{number_required + number_optional} arguments, but received #{number_generated}/)
155
+ end
152
156
  else
153
157
  assert false
154
158
  end
@@ -1,5 +1,6 @@
1
1
  require "minitest/autorun"
2
2
  require "gli"
3
+ require "pp"
3
4
 
4
5
  module TestHelper
5
6
  class CLIApp
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.21.5
4
+ version: 2.22.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: 2024-07-18 00:00:00.000000000 Z
11
+ date: 2024-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -238,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  - !ruby/object:Gem::Version
239
239
  version: '0'
240
240
  requirements: []
241
- rubygems_version: 3.5.15
241
+ rubygems_version: 3.5.22
242
242
  signing_key:
243
243
  specification_version: 4
244
244
  summary: Build command-suite CLI apps that are awesome.