You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried adding some raw(setting = "structopt::clap::AppSettings::AllowExternalSubcommands") here and there, but Opt::from_args() always shows the help then exits.
I don't think it can work without modification of structopt.
I don't see how it can work with the from_arg interface, as clap will not error but the subcommand can't be inserted inside your struct. What do you expect?
I'm actually trying to move from basic clap to structopt. I have a list of subcommands (hence the enum), but also external subcommands, that obviously can't be part of the enum since I don't know them at compile time.
I just wanted clarity here to see if I understood this issue to be mine as well...
I have a use case where I want to accept an arbitrary command after my command-line's options. Effectively, I think this makes it an external subcommand with a signature that looks something like this:
cli-cmd [FLAGS] <NAME> [<COMMAND>...]
COMMAND, for example, could be ls -lashtr some/path or possibly something like find . -name "*.rs"... it's arbitrary.
My initial go at this was to create a struct and then put one entry within the struct as a vector, but this seems to cause an error. After trying multiple lines in various configurations:
I just wanted clarity here to see if I understood this issue to be mine as well...
I have a use case where I want to accept an arbitrary command after my command-line's options.
That was actually not my case. My case was a command runner, similar to how git does it.
It has some built-in commands, like help and commands, but the rest are actually delegated to other processes.
So example help would parse as the Help command, but example foo bar would run example-foo bar. I would use this to be able to A) being able to oxidize a large collection of bash scripts over time (convert one command at a time), and B) to be able to let users of my app to extend it by adding their own commands to PATH and follow a specific convention with arguments.
Activity
TeXitoi commentedon Aug 7, 2018
I don't think it can work without modification of structopt.
I don't see how it can work with the from_arg interface, as clap will not error but the subcommand can't be inserted inside your struct. What do you expect?
nicompte commentedon Aug 7, 2018
Yes,
from_argdoesn't make much sense here.I've also tried this:
But
Opt::clap().get_matches()also shows the help then exits.And looking at my code, I see that
Optis an enum, which maybe doesn't help.TeXitoi commentedon Aug 13, 2018
Sorry for the long delay.
If you use an enum, the subcommand is required. That may be what is causing your problem?
nicompte commentedon Aug 28, 2018
Sorry for the long delay too :)
I'm actually trying to move from basic clap to structopt. I have a list of subcommands (hence the enum), but also external subcommands, that obviously can't be part of the enum since I don't know them at compile time.
I'll try to do something with
from_iter_safe.Mange commentedon Jan 31, 2019
What if one were to use something like this? Could this be a valid API surface?
TeXitoi commentedon Jan 31, 2019
@Mange seems a good candidate for this problem yes. Handling
OsStringis needed, but collecting in aVec<OsString>is feasible.brianbruggeman commentedon Aug 5, 2019
I just wanted clarity here to see if I understood this issue to be mine as well...
I have a use case where I want to accept an arbitrary command after my command-line's options. Effectively, I think this makes it an external subcommand with a signature that looks something like this:
COMMAND, for example, could bels -lashtr some/pathor possibly something likefind . -name "*.rs"... it's arbitrary.My initial go at this was to create a struct and then put one entry within the struct as a vector, but this seems to cause an error. After trying multiple lines in various configurations:
I'm still unable to find a method which seems to accept more than a single String or can convert to a vector of strings...
Some sample errors for different configurations...
TeXitoi commentedon Aug 15, 2019
This should do what you want, extra subcommand is different to your needs:
ahmed-masud commentedon Sep 14, 2019
Any interest in an implementation of this?
TeXitoi commentedon Sep 17, 2019
A PR adding this feature will be accepted. Any interested person can do it, but there is no work in progress as far as I know.
Mange commentedon Sep 17, 2019
That was actually not my case. My case was a command runner, similar to how
gitdoes it.It has some built-in commands, like
helpandcommands, but the rest are actually delegated to other processes.So
example helpwould parse as theHelpcommand, butexample foo barwould runexample-foo bar. I would use this to be able to A) being able to oxidize a large collection of bash scripts over time (convert one command at a time), and B) to be able to let users of my app to extend it by adding their own commands to PATH and follow a specific convention with arguments.CreepySkeleton commentedon Dec 3, 2019
I'm working on this, design is like following: