Replies: 1 comment
-
Currently, we don't track Cargo has a similar need but solves the problem in a different way. If you are curious, the code is at https://github.com/rust-lang/cargo/blob/340d1239a89d0030fd547beae74d87a1dccb8bd6/src/bin/cargo/cli.rs#L51 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm doing
matches.try_get_matches_from(&string_args)
withallow_external_subcommands
, where I will process the subcommand name by checking it against a table of aliases and updatestring_args
to resolve the alias to a different subcommand name plus some additional options. In order to do this correctly, I need the index of the subcommand withinstring_args
so I can truncatestring_args
to just before it, then extend it with the new command name plus additional args plus any arguments pushed on. Example:This is actually doable by counting the arguments passed to the subcommand (here,
--a
), dropping those off the end, dropping one more for the alias, and then adding things onto that stem. But I can't use that when my subcommands can have subcommands. I would like to do:I can find the subcommand index by searching through
string_args
, but I may run into something like["myapp", "--title", "myalias", "myalias"]
. So I thought I'd usematches.indices_of(id)
for all of the ids and remove all such indices from consideration. But as far as I can tell,indices_of
does not refer to elements ofstring_args
at all, but in some virtual list.Honestly, I don't understand what they refer to. The argv vs clap indices thing makes sense, but when I actually use it, it seems like it's returning indices well outside of my vector. My actual scenario:
Sorry, that's a lot of detail, but I was worried a simple question would end up being an X/Y problem. Those indices seem to be for... maybe the list of arguments in my Command? I don't even know what they are. Is it confused because "--two" isn't even a real option? (But it can't know what "myalias" should resolve to, so it can't know what is or isn't valid yet.) What is it doing?
Beta Was this translation helpful? Give feedback.
All reactions