gli 2.21.5 → 2.22.1

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: 7b0534e1da9392c5092cdab8ee34128952934c9460c065b252b49cc48e2bc65a
4
+ data.tar.gz: d662f3f40133767a6b83b6ec60af2bb20a2b6e9b359adf0cb116721530abe191
5
5
  SHA512:
6
- metadata.gz: '02638fe45837c6e17d83d8e1afaf3a90e94da181419b1dfc6f53db9487a90566ff281a2e9adc4155bd4baa379f5f43f379a716e788330e12f828ad2d9a233f99'
7
- data.tar.gz: fbd6c9281eaf31a203cf5f6331ce21f4241eeb6b7e8cfafc5c3c4d63e81455a60246d76aa411ec4c3ffee3137c48921c569b819f6e0b7cc0e95225c5cdf18a1f
6
+ metadata.gz: 10e1f59d2bc9b446c5ceb58781826e8b36a732f8ec046979517d0ca7d57097f2d6a7674ba219ae4d2786fcb87b51eda11fed4f933e683189578bf6a2a03f7c97
7
+ data.tar.gz: 1d157c1064f3d8a72f5a37af9b44d0d0aa021224dc758437b7490ef75a667cae7ddb14584efbe1083285a70277e20e51e360d1293ce08fa9afcccdfa78481d4e
data/dx/build CHANGED
@@ -37,6 +37,7 @@ log "🗑️" "Deleting previous ${compose_file}"
37
37
 
38
38
  rm -f "${compose_file}"
39
39
  echo "# THIS IS GENERATED - DO NOT EDIT" > "${compose_file}"
40
+ echo "# To make changes see dx/build or dx/docker-compose.env" >> "${compose_file}"
40
41
  echo "" >> "${compose_file}"
41
42
  echo "services:" >> "${compose_file}"
42
43
 
@@ -1,5 +1,5 @@
1
1
  # This array must include the oldest Ruby first!
2
- RUBY_VERSIONS=("3.1" "3.2" "3.3")
2
+ RUBY_VERSIONS=("3.2" "3.3" "3.4")
3
3
  IMAGE=davetron5000/gli-dev
4
4
  PROJECT_NAME=gli
5
5
  # vim: ft=bash
data/gli.gemspec CHANGED
@@ -31,6 +31,8 @@ spec = Gem::Specification.new do |s|
31
31
  s.bindir = "exe"
32
32
  s.executables = "gli"
33
33
 
34
+ s.add_dependency("ostruct")
35
+
34
36
  s.add_development_dependency("rake")
35
37
  s.add_development_dependency("rdoc")
36
38
  s.add_development_dependency("rainbow", "~> 1.1", "~> 1.1.1")
@@ -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,11 +98,9 @@ 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
107
105
  end
108
106
 
@@ -114,10 +112,7 @@ module GLI
114
112
  ( options[option.name].kind_of?(Array) && options[option.name].empty? )
115
113
  }
116
114
  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)
115
+ raise MissingRequiredOptionsException.new(command,missing_required_options)
121
116
  end
122
117
  end
123
118
  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.1'
4
4
  end
5
5
  end
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
@@ -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,15 +1,28 @@
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Copeland
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-07-18 00:00:00.000000000 Z
10
+ date: 2025-01-13 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ostruct
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: rake
15
28
  requirement: !ruby/object:Gem::Requirement
@@ -219,7 +232,6 @@ metadata:
219
232
  homepage_uri: https://davetron5000.github.com/gli/
220
233
  source_code_uri: https://github.com/davetron5000/gli/
221
234
  wiki_url: https://github.com/davetron5000/gli/wiki
222
- post_install_message:
223
235
  rdoc_options:
224
236
  - "--title"
225
237
  - Git Like Interface
@@ -238,8 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
250
  - !ruby/object:Gem::Version
239
251
  version: '0'
240
252
  requirements: []
241
- rubygems_version: 3.5.15
242
- signing_key:
253
+ rubygems_version: 3.6.2
243
254
  specification_version: 4
244
255
  summary: Build command-suite CLI apps that are awesome.
245
256
  test_files: []