ManageIQ / optimist

Optimist is a commandline option parser for Ruby that just gets out of your way.
https://manageiq.org/optimist/
MIT License
248 stars 36 forks source link

Using banner disables usage & synopsis #89

Open tiennou opened 7 years ago

tiennou commented 7 years ago

Example option block :

opts = Trollop::options do
  version 0.1

  usage "foo|bar"
  synopsis "Reticulate splines"

  banner "Recognized options: "
  opt :dry_run, "Don't do anything", short: "-n"
end

Output when passed --help is :

Recognized options: 
  -n, --dry-run    Don't do anything
  -v, --version    Print version and exit
  -h, --help       Show this message

If I comment just the banner line, I get this :

Usage: test foo|bar
Reticulate splines

0.1
Options:
  -n, --dry-run    Don't do anything
  -v, --version    Print version and exit
  -h, --help       Show this message

Additionally, I get warnings (the shebang line is #!/usr/bin/env ruby -W) depending on whether the usage or synopsis lines are comment out :

$gem-path/trollop-2.1.2/lib/trollop.rb:480: warning: instance variable @usage not initialized
$gem-path/trollop-2.1.2/lib/trollop.rb:481: warning: instance variable @synopsis not initialized
nanobowers commented 7 years ago

@tiennou I agree that the behavior is not intiutive, however it is documented in the Wiki with some examples: https://github.com/ManageIQ/trollop/wiki/Banner%2C-Synopsis-and-Version

The warnings should be fixed in PR #80

kbrock commented 6 years ago

Is there a suggestion on how it should behave?

tiennou commented 6 years ago

I suggest that banner, being an alias of text, shouldn't prevent usage & synopsis from working, so we get to have both nice, automated synopsises as well as free-form text. Would that be acceptable ?

From a backward-compatibility POV, I don't think it would have a big impact, seeing as it's either banner/text OR usage/synopsis, you would have skimmed over the former as soon as you were to use the latter.

kbrock commented 6 years ago

I'm mixed on this one.

I had thought that banner is used to define your own header. If you didn't provide it, the system would create one using version, usage and synopsis

@Fryguy you see any downside to always producing header information even when banner is added.