From a5c22063cda68c502c1b5cdb75ec21be1e1d270a Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 1 May 2022 18:12:41 +0530 Subject: [PATCH] refactor: switch to argv for argument handling --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 8 ++------ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 633cbda..87d3a05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,12 @@ version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" +[[package]] +name = "argv" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "593b6306f88ed573d52d5d07e309317f1c5e95777bf559b2ddb33f50b7d1158d" + [[package]] name = "assay" version = "0.1.1" @@ -86,6 +92,7 @@ name = "clipboard-substitutor" version = "0.5.0" dependencies = [ "anyhow", + "argv", "assay", "clipboard-master", "copypasta", diff --git a/Cargo.toml b/Cargo.toml index d4e93cc..432cfcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ include = ["src/**/*", "LICENSE-*", "README.md"] [dependencies] anyhow = "1.0.57" +argv = "0.1.5" clipboard-master = "3.1.3" copypasta = { version = "0.7.1", default-features = false, features = ["x11"] } dirs = "4.0.0" diff --git a/src/main.rs b/src/main.rs index 9675d81..c431cd0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ mod config; #[cfg(test)] mod test; -use std::ops::Deref; use std::path::PathBuf; use anyhow::{anyhow, Result}; @@ -12,8 +11,6 @@ use dirs::config_dir; use crate::clipboard::monitor_clipboard; use crate::config::Replacements; -const VERSION_ARGS: [&str; 3] = ["version", "-v", "--version"]; - fn main() -> Result<()> { if check_for_version_arg() { return Ok(()); @@ -28,9 +25,8 @@ fn main() -> Result<()> { } fn check_for_version_arg() -> bool { - let args: Vec = std::env::args().collect(); - for arg in args { - if VERSION_ARGS.contains(&arg.deref()) { + for arg in argv::iter() { + if arg == "-v" || arg == "version" || arg == "--version" { print_version(); return true; }