Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for docopt style help #56

Open
zeteref opened this issue Jun 17, 2022 · 3 comments
Open

add support for docopt style help #56

zeteref opened this issue Jun 17, 2022 · 3 comments

Comments

@zeteref
Copy link

zeteref commented Jun 17, 2022

It would be nice if cod could learn help in the format proposed by docopt http://docopt.org/

for example if i try to make cod learn their default example:

$ ./naval_fate --help
Naval Fate.

Usage:
  naval_fate ship new <name>...
  naval_fate ship <name> move <x> <y> [--speed=<kn>]
  naval_fate ship shoot <x> <y>
  naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate -h | --help
  naval_fate --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.
┌──> /tmp/naval_fate --help                                                                                                                                                                                                         
└─── cod: learn this command? [yn?] > y
cod: learned completions: "--speed=" "--moored" "--drifting" and 3 more

Only flag options are learned. However I'm not sure how wildly spread the docopt format actually is...

@dim-an
Copy link
Owner

dim-an commented Jun 17, 2022

It is nice idea, I looked at docopt some time ago, but I don't use docopt myself. Do you use it in your projects?

@zeteref
Copy link
Author

zeteref commented Jun 17, 2022

I try to but I fail a lot :D. It seems to be the only well defined specification for writing help texts that i can find so everytime i need to write help i end up looking at docopt

Perhaps i will try to make a pull request, i was wanting to learn go for a while now anyways...

@dim-an
Copy link
Owner

dim-an commented Jun 17, 2022

PRs are welcome :)

Here is list of supported parsers:

https://github.com/dim-an/cod/blob/master/parse_doc/parse_help.go#L30-L33

Last one is default parser that parses everything. Special parsers go before default parser (right now we only have argparse parser). They return error if they think that they don't support current help text.

res, err = parsers[idx].Parse(ctx)

You can get inspiration from argparse parser and its test.

func (argparseParser) Parse(context parseContext) (res *parseResult, err error) {

https://github.com/dim-an/cod/blob/de10c9bfff394dd59f302515776f1413f26e5a49/parse_doc/argparse_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants