generated from alecodes/base-template
feat: add clap arg parse
This commit is contained in:
parent
ccac3478f7
commit
57074a89ff
3 changed files with 271 additions and 2 deletions
|
|
@ -1,3 +1,34 @@
|
|||
fn main() {
|
||||
println!("Hello from cli bin!");
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
#[command(propagate_version = true)]
|
||||
struct Cli {
|
||||
/// Name of the person to greet
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
|
||||
#[arg(short = 'u', long, global = true, env = "CLI_DB_URL")]
|
||||
db_url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
/// Executes a query agains the database, it pass it directly to the underliying driver
|
||||
Query {
|
||||
/// Query to execute
|
||||
sql: String,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
// You can check for the existence of subcommands, and if found use their
|
||||
// matches just as you would the top level cmd
|
||||
match &cli.command {
|
||||
Commands::Query { sql } => {
|
||||
println!("Provided query: {sql:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue