-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Support for multicall binaries #1120
Comments
Thanks for the suggestion! This could be done in two ways, either an external crate that uses clap internally and just matches If you'd like to test the The basic premise would be However, if it doesn't match, you could check that it matches a subcommand name and set Here's how you can add those specifics:
At the end I envision this working: let matches = App::new("q")
.setting(AppSettings::Multicall)
.subcommand(SubCommand::with_name("foo")
.arg(Arg::from_usage("-f, --foo-flag 'some foo flag'")))
.subcommand(SubCommand::with_name("bar")
.arg(Arg::from_usage("-b, --bar-flag 'some bar flag'")))
.arg(Arg::from_usage("-q, --q-flag 'some q flag'"))
.get_matches(); And being able to work with any of these
|
Note this also somewhat similar to #975 |
Thanks for the feedback, it was more detailed than expected! I started code-wrangling based on your hints and I have a few more questions.
This seems to be the busybox-style applets approach, where
I'm having some difficulties following how this would work. First, I assume you mean |
I did a bit of digging in the ticket tracker, but I didn't see this topic covered before. In short, I would like to explore how to support multicall binaries in clap.
Multicall binaries share a single codebase, but different codepaths can be activated based on
basename(argv[0])
. A good example to target would be thehostname
util: https://sources.debian.net/src/hostname/3.18/hostname.c/#L6-L12.What I would like to be able to do with clap is:
All of this in order in order to use normal clap features transparently in a multicall binary. This can be already done with a bit of boilerplate (here a very dirty example), but if possible I'd like to see this directly supported in clap as I've found myself repeating this logic in several places lately.
I'll be happy to try contribute code/test/review for this, but it will need design inputs from @kbknapp first.
PS: thanks for maintaining clap, it is a great library!
The text was updated successfully, but these errors were encountered: