From a72b4bee5c585afa65216310fe7d392fc85ad654 Mon Sep 17 00:00:00 2001 From: Nydragon Date: Wed, 22 May 2024 08:34:27 +0900 Subject: [PATCH] fix: handling arg passed by rofi --- Cargo.lock | 38 +++++++++++++++++++------------------- Cargo.toml | 2 +- src/args.rs | 25 +++++++++++++++++++++---- src/main.rs | 8 ++++---- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82e7aef..d8ae56c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,9 +53,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.82" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "clap" @@ -183,9 +183,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "memchr" @@ -201,9 +201,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "open" -version = "5.1.2" +version = "5.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "449f0ff855d85ddbf1edd5b646d65249ead3f5e422aaa86b7d2d0b049b103e32" +checksum = "2eb49fbd5616580e9974662cb96a3463da4476e649a7e4b258df0de065db0657" dependencies = [ "is-wsl", "libc", @@ -224,9 +224,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" dependencies = [ "unicode-ident", ] @@ -242,7 +242,7 @@ dependencies = [ [[package]] name = "rofi-obsidian" -version = "0.1.2" +version = "0.1.3" dependencies = [ "anyhow", "clap", @@ -255,24 +255,24 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" dependencies = [ "proc-macro2", "quote", @@ -281,9 +281,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -307,9 +307,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.58" +version = "2.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "d2863d96a84c6439701d7a38f9de935ec562c8832cc55d1dde0f513b52fad106" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 8eade66..8164fcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rofi-obsidian" description = "Launch your Obsidian vaults from the comfort of rofi" -version = "0.1.2" +version = "0.1.3" edition = "2021" license = "Unlicense" readme = "README.md" diff --git a/src/args.rs b/src/args.rs index 77a4be4..ff61812 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,18 +1,35 @@ -use clap::{Parser, Subcommand}; +use std::fmt::Display; -#[derive(Debug, Clone, Subcommand)] +use clap::{Parser, ValueEnum}; + +#[derive(Debug, Clone, Default, ValueEnum)] pub enum SubCommand { /// Initiate the configuration at the default location InitConfig, /// Edit the configuration Config, /// Run rofi-obsidian, default behaviour + #[default] Run, } +impl Display for SubCommand { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let sub = match *self { + SubCommand::Run => "run", + SubCommand::Config => "config", + SubCommand::InitConfig => "init-config", + }; + + write!(f, "{}", sub) + } +} + #[derive(Parser, Debug)] #[command(author, version, about)] pub struct Args { - #[command(subcommand)] - pub sub: Option, + #[clap(long, short, default_value_t = SubCommand::default())] + pub command: SubCommand, + #[clap()] + pub selection: Option, } diff --git a/src/main.rs b/src/main.rs index 781bbe3..5707752 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,15 +122,15 @@ fn main() -> Result<()> { let conf = config::Config::parse(); let args = Args::parse(); - match args.sub { - Some(SubCommand::InitConfig) => { + match args.command { + SubCommand::InitConfig => { let location = conf.write()?; println!("Config written to: {:?}", location); } - Some(SubCommand::Config) => { + SubCommand::Config => { unimplemented!() } - Some(SubCommand::Run) | None => { + SubCommand::Run => { if let Ok(state) = env::var("ROFI_RETV") { let state = state.parse()?; rofi_main(state, conf, args)?;