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)?;