Skip to content

Commit

Permalink
use clap to get the COMMA_PICKER env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Artturin committed Apr 18, 2022
1 parent ddee13f commit 98043ec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 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
Expand Up @@ -9,4 +9,4 @@ license = "MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = "3.1.9"
clap = { version = "3.1.9", features = ["env"]}
13 changes: 7 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ fn main() {
.takes_value(false)
.help("install the derivation containing the executable"),
)
.arg(Arg::new("picker")
.long("picker")
.env("COMMA_PICKER")
.takes_value(true)
.default_value("fzy")
)
.trailing_var_arg(true)
.arg(arg!(<cmd> ... "command to run"))
.get_matches();

let picker = match env::var("COMMA_PICKER") {
Ok(val) => val,
Err(_) => "fzy".to_string(),
};

let install = matches.is_present("install");

let mut trail: Vec<&str> = matches.values_of("cmd").unwrap().collect();
Expand All @@ -94,7 +95,7 @@ fn main() {
.collect();

let choice = if attrs.len() != 1 {
pick(&picker, attrs)
pick(matches.value_of("picker").unwrap(), attrs)
} else {
attrs.first().unwrap().trim().to_string()
};
Expand Down

0 comments on commit 98043ec

Please sign in to comment.