davetron5000 / gli

Make awesome command-line applications the easy way
http://davetron5000.github.io/gli
Apache License 2.0
1.26k stars 102 forks source link

Question: Matching flag names #295

Closed micahlee closed 3 years ago

micahlee commented 4 years ago

Hello,

I recently discovered that with a CLI built using GLI, the flag arguments will match when the flag given is not an exact match. Flags that our different cases, or are a substring of the defined flag will also match.

For example, if I define a flag like:

c.flag [:p, "admin-password"]

Then it will accept the flag as expected with either -p or --admin-password. However, it will also match the same flag with --admin-p.

Is this the expected behavior for flag name matching? Is there a way to make the matching strict, such that substrings are not accepted?

Thanks so much!

davetron5000 commented 4 years ago

It looks like this is behavior of Ruby's OptionParse. TIL:

> cat test.rb
require "optparse"
options = {}
OptionParser.new { |opts|
  opts.on("--version") do |v|
    options[:version] = true
  end
}.parse!

puts options.inspect

> ruby test.rb --version
{:version=>true}

> ruby test.rb --ver
{:version=>true}
micahlee commented 4 years ago

Ah, that would explain why I couldn't figure out where this was handled in GLI. 😆 Thanks!