From 8c02343737f4f980dc4e28f3892ed75d07527816 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 13 Mar 2022 13:07:09 +0100 Subject: main(): Add subcommands and arguments Trying to match the subcommand enum, but apparently can't get a variant (`Command::Insert`) out of the `@` binding, it seems it ends up being a `Command` type. --- src/main.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index b770fa9..d12015a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,19 +4,31 @@ use yaml_rust::yaml; #[derive(clap::Parser, Debug)] -#[clap()] +#[clap(version)] struct Args { #[clap(subcommand)] command: Command, - - #[clap(long)] - database: String, } #[derive(clap::Subcommand, Debug)] enum Command { - Insert, - Select, + Insert { + #[clap(long)] + database: String, + + table_name: String, + + input_file: Option, + }, + + Select { + #[clap(long)] + database: String, + + table_name: String, + + record_id: String, + }, } @@ -27,6 +39,14 @@ fn main() { // Get column names from SQLite + match args.command { + a @ Command::Insert { .. } => { + dbg!(a.database); + } + + a @ Command::Select { .. } => {} + }; + let mut dbconn = rusqlite::Connection::open("./test.db").unwrap(); let text_data = std::fs::read_to_string("test2.yml").unwrap(); -- cgit v1.2.3