Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handling arg passed by rofi #11

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading