docopt.hs icon indicating copy to clipboard operation
docopt.hs copied to clipboard

Make usage-/help-string behavior consistent with original `docopt`

Open jpdoyle opened this issue 1 year ago • 1 comments

Fixes https://github.com/docopt/docopt.hs/issues/32.

(moved from https://github.com/docopt/docopt.hs/pull/50 -- it looks like it'll need a few more edits now since 2.5 years ago :) )

This makes 3 main changes to this library's behavior:

  1. pUsagePatterns (and thus pDocopt) parses out the "Usage:" section of the helpstring as a string and returns that. The way I'm parsing it feels really hacky but I wasn't sure a better way to achieve it.
  2. exitWithUsage and exitWithUsaegMessage now print that "short usage string" rather than the whole helpstring. exitWithHelpstring has been added, which prints the whole helpstring.
  3. parseArgsOrExit automatically exits printing the helpstring if longOption "help" is present, to be more consistent with the original docopt behavior. I'm not sure this is the correct place in the library to put it, but it creates the intended behavior.

jpdoyle avatar Feb 24 '24 17:02 jpdoyle

Ah, thank you for opening a new PR!

DigitalBrains1 avatar Feb 25 '24 09:02 DigitalBrains1