mirror of
https://github.com/msfjarvis/clipboard-substitutor
synced 2025-08-14 21:17:01 +05:30
main: support various version CLI flags
This commit is contained in:
parent
675b90f226
commit
358e54b897
1 changed files with 22 additions and 0 deletions
22
src/main.rs
22
src/main.rs
|
@ -16,10 +16,32 @@ fn main() -> Result<()> {
|
|||
let config_path = get_config_path()?;
|
||||
let config_str = std::fs::read_to_string(config_path.as_path()).unwrap_or_default();
|
||||
let config: Replacements<'_> = toml::from_str(&config_str)?;
|
||||
if check_args() {
|
||||
return Ok(());
|
||||
}
|
||||
loop_clipboard(config);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fn check_args() -> bool {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let version_args = vec!["version", "-v", "--version"];
|
||||
for arg in args {
|
||||
if version_args.contains(&arg.deref()) {
|
||||
print_version();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
fn print_version() {
|
||||
println!(
|
||||
"{}",
|
||||
concat!(env!("CARGO_PKG_NAME"), " ", env!("CARGO_PKG_VERSION"))
|
||||
);
|
||||
}
|
||||
|
||||
fn get_config_path() -> Result<PathBuf> {
|
||||
let mut config_path = config_dir().ok_or_else(|| anyhow!("Failed to get config dir"))?;
|
||||
config_path.push("substitutor");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue