Skip to content

Commit

Permalink
Flip polarity of explicit_short_opts: false to implicit_short_opts: true
Browse files Browse the repository at this point in the history
  • Loading branch information
nanobowers committed May 10, 2024
1 parent 45b4725 commit 60f2f2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/optimist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def self.registry_getopttype(type)

DEFAULT_SETTINGS = {
exact_match: true,
explicit_short_opts: false,
implicit_short_opts: true,
suggestions: true
}

Expand Down Expand Up @@ -317,7 +317,7 @@ def parse(cmdline = ARGV)
vals[sym] = [] if opts.multi && !opts.default # multi arguments default to [], not nil
end

resolve_default_short_options! unless @settings[:explicit_short_opts]
resolve_default_short_options! if @settings[:implicit_short_opts]

## resolve symbols
given_args = {}
Expand Down Expand Up @@ -1031,7 +1031,7 @@ def multi_arg? ; true ; end
## +settings+ include:
## * :exact_match : (default=true) Allow minimum unambigous number of characters to match a long option
## * :suggestions : (default=true) Enables suggestions when unknown arguments are given and DidYouMean is installed. DidYouMean comes standard with Ruby 2.3+
## * :explicit_short_opts : (default=false) Short options will only be created where explicitly defined. If you do not like short-options, this will prevent having to define :short=> :none for all of your options.
## * :implicit_short_opts : (default=true) Short options will only be created where explicitly defined. If you do not like short-options, this will prevent having to define :short=> :none for all of your options.
## Because Optimist::options uses a default argument for +args+, you must pass that argument when using the settings feature.
##
## See more examples at https://www.manageiq.org/optimist
Expand Down
8 changes: 4 additions & 4 deletions test/optimist/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ def test_default_shorts_assigned_only_after_user_shorts
end

def test_short_opts_not_implicitly_created
newp = Parser.new(explicit_short_opts: true)
newp = Parser.new(implicit_short_opts: false)
newp.opt :user1, "user1"
newp.opt :bag, "bag", :short => 'b'
assert_raises(CommandlineError) do
Expand All @@ -1191,9 +1191,9 @@ def test_short_opts_not_implicitly_created
end

def test_short_opts_not_implicit_help_ver
# When explicit_short_opts is enabled this extends
# to the built-in help/version also.
newp = Parser.new(explicit_short_opts: true)
# When implicit_short_opts is false this implies the short options
# for the built-in help/version are also not created.
newp = Parser.new(implicit_short_opts: false)
newp.opt :abc, "abc"
newp.version "3.4.5"
assert_raises(CommandlineError) do
Expand Down

0 comments on commit 60f2f2e

Please sign in to comment.