Skip to content

Command derive setup for both cargo extension and standalone usage #5107

Answered by epage
MiniaczQ asked this question in Q&A
Discussion options

You must be logged in to vote

Would the following work?

#!/usr/bin/env nargo

/*!
```cargo
[dependencies]
clap = { version = "4", features = ["derive"] }
```
*/

use clap::Parser;

#[derive(Debug, Parser)]
#[command(name = "cargo-tarpaulin")]
#[command(bin_name = "cargo")]
#[command(author, version, about, long_about = None)]
pub enum CargoTarpaulinCli {
    Tarpaulin(TarpaulinCli),
}

#[derive(Debug, Parser)]
pub struct TarpaulinCli {}

fn main() {
    let cli = match CargoTarpaulinCli::try_parse() {
        Ok(CargoTarpaulinCli::Tarpaulin(tarpaulin_cli)) => tarpaulin_cli,
        Err(err) if !err.use_stderr() => err.exit(),
        Err(_) => TarpaulinCli::parse(),
    };
    dbg!(cli);
}

We bubble --version and --help

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by MiniaczQ
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants