in sources/api/apiclient/src/main.rs [328:366]
fn parse_exec_args(args: Vec<String>) -> Subcommand {
let mut command = vec![];
let mut target = None;
let mut tty = None;
let mut iter = args.into_iter();
while let Some(arg) = iter.next() {
match arg.as_ref() {
// Check for our own arguments, but stop once we start to see the user's command; we
// don't want to intercept its own arguments.
"-t" | "--tty" if command.is_empty() => {
tty = Some(true);
}
"-T" | "--no-tty" if command.is_empty() => {
tty = Some(false);
}
x if x.starts_with('-') && command.is_empty() => {
usage_msg(&format!("Unknown argument '{}'", x))
}
// Target is the first arg we see.
_ if target.is_none() => target = Some(arg),
// Anything remaining goes to the command.
_ => command.push(arg.into()),
}
}
// (check target here because it's clearer to error about it before an error about a missing command)
let target = target.unwrap_or_else(|| usage_msg("Missing required argument 'target'"));
if command.is_empty() {
usage_msg("Must specify a command for 'exec' to run.");
}
Subcommand::Exec(ExecArgs {
command,
target,
tty,
})
}