How to load binaries like cargo-web.exe in Clap?

Is it possible to interrupt parsing after astro air, for example, once it ultrapasses 'air'?

extern crate clap;
use clap::{App, Arg, ArgGroup, SubCommand};

// mod config;
// mod storage;

fn main() {
    let app = App::new("Astro")
            .arg(Arg::from_usage("--bin [dev-type]").group("type"))
            .arg(Arg::from_usage("--lib [dev-type]").group("type"))

    // Got to figure in how to add sym-link
    // commands w/ clap.
//  storage::devtools::commands(&app);

    let matches = app.get_matches();

    match matches.subcommand_name() {
        Some("new") => println!("Rant new"),
        Some("air") => println!("{}", std::env::args().nth(0).unwrap().as_str()),
        None => (),
        _ => println!("Missing impl")

Not really working.

So far I didn’t find anything related in Cargo’s source (this is where all the CLI goes). To clarify I want to know how cargo web works. How does cargo-web.exe runs as a subcommand in cargo if it’s not a built-in one?

It looks like my GitHub issue won’t be answered too and I’m not wanting to waste time again like my threwn away parsers.

If I’m reading the source correctly, cargo matches on clap errors and if it’s an unrecognized subcommand, it will try to execute an external binary cargo-<subcommandname>:

and execute_external_subcommand:

There’s probably more to it than just this, but the rest can probably be found by digging around in cargo’s source searching for usages of execute_external_subcommand and the like?


It’s not always ::UnrecognizedSubcommand, so…

if let Err(err) = result {
        match err.kind {
            | ErrorKind::UnknownArgument => {
                let name = &[0];
                println!("Probably air");
            _ => {
                if err.use_stderr() {