Skip to content

Commit

Permalink
Merge pull request #327 from davetron5000/required-flags-multiple-han…
Browse files Browse the repository at this point in the history
…dles-empty-array

required flags multiple handles empty array
  • Loading branch information
davetron5000 authored Jul 16, 2024
2 parents 85cba55 + d25de9c commit aaf5a36
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dx/build
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ log "✨" "Creating docker-compose.dx.yml"
compose_file="docker-compose.dx.yml"
log "🗑️" "Deleting previous ${compose_file}"

rm "${compose_file}"
rm -f "${compose_file}"
echo "# THIS IS GENERATED - DO NOT EDIT" > "${compose_file}"
echo "" >> "${compose_file}"
echo "services:" >> "${compose_file}"
Expand All @@ -54,7 +54,7 @@ for ruby_version in ${RUBY_VERSIONS[@]}; do
echo " entrypoint: /root/show-help-in-app-container-then-wait.sh" >> "${compose_file}"
echo " working_dir: /root/work" >> "${compose_file}"
done
log "🎼" "${compose_file} is noq created"
log "🎼" "${compose_file} is now created"
log "🔄" "You can run dx/start to start it up, though you may need to stop it first with Ctrl-C"

# vim: ft=bash
7 changes: 4 additions & 3 deletions lib/gli/gli_option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ def verify_arguments!(arguments, command)
def verify_required_options!(flags, command, options)
missing_required_options = flags.values.
select(&:required?).
reject { |option|
options[option.name] != nil
}
select { |option|
options[option.name] == nil ||
( options[option.name].kind_of?(Array) && options[option.name].empty? )
}
unless missing_required_options.empty?
missing_required_options.sort!
raise MissingRequiredArgumentsException.new(missing_required_options.map { |option|
Expand Down
2 changes: 1 addition & 1 deletion lib/gli/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module GLI
unless const_defined? :VERSION
VERSION = '2.21.2'
VERSION = '2.21.3'
end
end
39 changes: 39 additions & 0 deletions test/unit/gli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ def test_command_options_can_be_required

end

def test_command_options_accepting_multiple_values_can_be_required
@app.reset
@called = false
@app.command :foo do |c|
c.flag :flag, :required => true, :multiple => true
c.action do |global, options, arguments|
@called = true
end
end
assert_equal 64, @app.run(['foo']), "Expected exit status to be 64"
assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
assert !@called

assert_equal 0, @app.run(['foo','--flag=bar']), "Expected exit status to be 0 #{@fake_stderr.strings.join(',')}"
assert @called

end

def test_global_options_can_be_required
@app.reset
@called = false
Expand All @@ -102,6 +121,25 @@ def test_global_options_can_be_required

end

def test_global_options_accepting_multiple_can_be_required
@app.reset
@called = false
@app.flag :flag, :required => true, :multiple => true
@app.command :foo do |c|
c.action do |global, options, arguments|
@called = true
end
end
assert_equal 64, @app.run(['foo']), "Expected exit status to be 64"
assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
assert !@called

assert_equal 0, @app.run(['--flag=bar','foo']), "Expected exit status to be 0 #{@fake_stderr.strings.join(',')}"
assert @called

end

def test_global_required_options_are_ignored_on_help
@app.reset
@called = false
Expand Down Expand Up @@ -161,6 +199,7 @@ def test_init_from_config
raise failure if !failure.nil?
end


def test_command_line_overrides_config
failure = nil
@app.reset
Expand Down

0 comments on commit aaf5a36

Please sign in to comment.