-
Notifications
You must be signed in to change notification settings - Fork 11
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
port CLI from argh to bpaf #185
Conversation
this is a work-in-progress port from argh to bpaf. I am not convinced bpaf is a good solution here. First, I don't see an obvious way to have optional subcommands and global options. For example: hyperlink -j 4 dump-paragraphs -f foo.md ...should parse the same -j as: hyperlink -j 4 ./public/ in argh this worked fine (even though dump-paragraphs does not use -j right now), but in bpaf I didn't find a way to write subcommands without making them mutually exclusive with global options. additionally, a main reason I would like to move away from argh is its poor handling of help texts compared to clap. The helptext for dump-paragraphs currently looks like this: $ ./target/release/hyperlink dump-paragraphs --help Usage: hyperlink dump-paragraphs --file <file> Dump out internal data for markdown or html file. This is mostly useful to figure out why a source file is not properly matched up with its target html file. NOTE: This is a tool for debugging and development. Usage: vimdiff <(hyperlink dump-paragraphs src/foo.md) <(hyperlink dump-paragraphs public/foo.html) Each line on the left represents a Markdown paragraph. Each line on the right represents a HTML paragraph. If there are minor formatting differences in two lines that are supposed to match, you found the issue that needs fixing in `src/paragraph.rs`. There may also be entire lines missing from either side, in which case the logic for detecting paragraphs needs adjustment, either in `src/markdown.rs` or `src/html.rs`. Note that the output for HTML omits paragraphs that do not have links, while for Markdown all paragraphs are dumped. Options: --file markdown or html file --help display usage information This, from argh, is a mess, but bpaf is worse: $ ./target/debug/hyperlink dump-paragraphs --help Dump out internal data for markdown or html file. Usage: hyperlink dump-paragraphs --file=ARG Available options: --file=ARG markdown or html file -h, --help Prints help information Where did all that content go? It seems bpaf just drops all data after the first paragraph. I looked at the docs and found that bpaf has some special handling for two successive blank lines, but I don't have those in my code (only single blank line). Overall I found the API surface overwhelming and confusing. I can mix and match the derive and combinators API, and that led me very far astray when I couldn't figure out easily how to make optional subcommands work. I still don't really know how to make it work exactly the same as in argh/clap.
Normally you'd define a parser for a subcommand as if it was a required then add it to the top level with a combination of
Two successive blank lines separate "header", "description" and "footer" parts of the top level option parser. For all other help bits a single blank line separates "brief help" from "detailed help" - you can pass |
Sorry about that, writing documentation is hard :) It's all about some simple parsers created with |
Anyway, if you have questions - I'm happy to help. |
Thank you for directly engaging with this feedback! Another thing i found is that bpaf derive does not have good error messages. I get things like:
Here the issue was that the I now updated the CLI to use your suggested structure for optional subcommands. However, this does not actually work as I also have an optional base-path argument. The help looks like this:
There's a few issues:
this is very unexpected. is there a way to turn this off? I want to show one paragraph for each subcommand on I couldn't find any documentation for this behavior, and even if bpaf did document it, I think my users won't expect it. I personally don't know of any CLI that handles
I do think the architecture makes sense, but for getting started I would prefer a focus on realistic, large examples instead of three separate tutorials: one how to parse an option, one how to parse a subcommand, and then one generic tutorial that tells you hwo to combine arbitrary parsers. While this shows the composability really well it also requires me to put the pieces together myself. One tutorial that goes step-by-step on how to build something really complex like a clone of the git CLI (or the cargo CLI or even the npm CLI) would help here. |
I went with a suggestion from @Dav1dde to use a wrapper struct around my command enum, and it works fine (and the helptext seems correct) |
this helptext is ok but still formatted in an unfortunate way:
(the line-break is there) |
Hmm... I guess I can improve this error with
Not at the moment. Might be easier in upcoming 0.10. I'd skip those blank lines and force linebreaks in places you want with a single space
Should be included in any
Will see what I can do. There's a bunch of stuff in
It tries to fit everything within a fixed width and there's no fancy logic about line breaking. There's a ticket about it though, but I'm not sure how to do it yet :) You can hide some items from the generated usage line ( |
the link to the help() method contained sufficient information to make this work. I am a bit uncomfortable contorting the sourcecode to get multi-paragraph help by default, but it works. ty! |
This should be just |
I found that the output is not what I want ( |
Interesting problem, never thought about it this way. Made pacak/bpaf#409 - should be doable in 0.10 once it's done. |
context: #184 #176
fixes #184
this is a work-in-progress port from argh to bpaf. I am not convinced
bpaf is a good solution here.
First, I don't see an obvious way to have optional subcommands and
global options. For example:
...should parse the same -j as:
in argh this worked fine (even though dump-paragraphs does not use -j
right now), but in bpaf I didn't find a way to write subcommands without
making them mutually exclusive with global options.
additionally, a main reason I would like to move away from argh is its
poor handling of help texts compared to clap. The helptext for
dump-paragraphs currently looks like this:
This, from argh, is a mess, but bpaf is worse:
Where did all that content go? It seems bpaf just drops all data after
the first paragraph. I looked at the docs and found that bpaf has some
special handling for two successive blank lines, but I don't have those
in my code (only single blank line).
Overall I found the API surface overwhelming and confusing. I can mix
and match the derive and combinators API, and that led me very far
astray when I couldn't figure out easily how to make optional
subcommands work. I still don't really know how to make it work exactly
the same as in argh/clap.