mirror of
https://github.com/icewind1991/ykoauth-cli.git
synced 2026-06-03 20:14:08 +02:00
make clipboard optional
This commit is contained in:
parent
0af7a17d7b
commit
ac7d633ec3
2 changed files with 18 additions and 4 deletions
|
|
@ -10,4 +10,8 @@ ykoath = { version = "0.1.0", git = "https://github.com/icewind1991/ykoath-rs",
|
|||
anyhow = "1"
|
||||
chrono = "0.4"
|
||||
fuzzy_finder = "0.3.0"
|
||||
cli-clipboard = "0.3.0"
|
||||
cli-clipboard = { version = "0.3.0", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["clipboard"]
|
||||
clipboard = ["cli-clipboard"]
|
||||
16
src/main.rs
16
src/main.rs
|
|
@ -47,11 +47,21 @@ fn main() -> anyhow::Result<()> {
|
|||
}
|
||||
};
|
||||
|
||||
if let Err(_) = cli_clipboard::set_contents(code.to_string()) {
|
||||
println!("{}", code);
|
||||
} else {
|
||||
if try_copy(code.to_string()) {
|
||||
println!("{} - Copied", code);
|
||||
} else {
|
||||
println!("{}", code);
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue