make clipboard optional

This commit is contained in:
Robin Appelman 2023-02-03 20:11:27 +01:00
commit ac7d633ec3
2 changed files with 18 additions and 4 deletions

View file

@ -10,4 +10,8 @@ ykoath = { version = "0.1.0", git = "https://github.com/icewind1991/ykoath-rs",
anyhow = "1" anyhow = "1"
chrono = "0.4" chrono = "0.4"
fuzzy_finder = "0.3.0" fuzzy_finder = "0.3.0"
cli-clipboard = "0.3.0" cli-clipboard = { version = "0.3.0", optional = true }
[features]
default = ["clipboard"]
clipboard = ["cli-clipboard"]

View file

@ -47,11 +47,21 @@ fn main() -> anyhow::Result<()> {
} }
}; };
if let Err(_) = cli_clipboard::set_contents(code.to_string()) { if try_copy(code.to_string()) {
println!("{}", code);
} else {
println!("{} - Copied", code); println!("{} - Copied", code);
} else {
println!("{}", code);
} }
Ok(()) Ok(())
} }
#[cfg(feature = "clipboard")]
fn try_copy(code: String) -> bool {
cli_clipboard::set_contents(code).is_ok()
}
#[cfg(not(feature = "clipboard"))]
fn try_copy(_code: String) -> bool {
false
}