Skip to content

Commit

Permalink
fix: handling arg passed by rofi
Browse files Browse the repository at this point in the history
  • Loading branch information
Nydragon committed May 21, 2024
1 parent beafaad commit 4d49629
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
38 changes: 19 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
25 changes: 21 additions & 4 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -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,
/// <unimplemented> 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<SubCommand>,
#[clap(long, short, default_value_t = SubCommand::default())]
pub command: SubCommand,
#[clap()]
pub selection: Option<String>,
}
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down

0 comments on commit 4d49629

Please sign in to comment.