refactor: switch to argv for argument handling

This commit is contained in:
Harsh Shandilya 2022-05-01 18:12:41 +05:30
parent 1a1e97722b
commit a5c22063cd
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
3 changed files with 10 additions and 6 deletions

7
Cargo.lock generated
View file

@ -26,6 +26,12 @@ version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
[[package]]
name = "argv"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "593b6306f88ed573d52d5d07e309317f1c5e95777bf559b2ddb33f50b7d1158d"
[[package]] [[package]]
name = "assay" name = "assay"
version = "0.1.1" version = "0.1.1"
@ -86,6 +92,7 @@ name = "clipboard-substitutor"
version = "0.5.0" version = "0.5.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"argv",
"assay", "assay",
"clipboard-master", "clipboard-master",
"copypasta", "copypasta",

View file

@ -13,6 +13,7 @@ include = ["src/**/*", "LICENSE-*", "README.md"]
[dependencies] [dependencies]
anyhow = "1.0.57" anyhow = "1.0.57"
argv = "0.1.5"
clipboard-master = "3.1.3" clipboard-master = "3.1.3"
copypasta = { version = "0.7.1", default-features = false, features = ["x11"] } copypasta = { version = "0.7.1", default-features = false, features = ["x11"] }
dirs = "4.0.0" dirs = "4.0.0"

View file

@ -3,7 +3,6 @@ mod config;
#[cfg(test)] #[cfg(test)]
mod test; mod test;
use std::ops::Deref;
use std::path::PathBuf; use std::path::PathBuf;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
@ -12,8 +11,6 @@ use dirs::config_dir;
use crate::clipboard::monitor_clipboard; use crate::clipboard::monitor_clipboard;
use crate::config::Replacements; use crate::config::Replacements;
const VERSION_ARGS: [&str; 3] = ["version", "-v", "--version"];
fn main() -> Result<()> { fn main() -> Result<()> {
if check_for_version_arg() { if check_for_version_arg() {
return Ok(()); return Ok(());
@ -28,9 +25,8 @@ fn main() -> Result<()> {
} }
fn check_for_version_arg() -> bool { fn check_for_version_arg() -> bool {
let args: Vec<String> = std::env::args().collect(); for arg in argv::iter() {
for arg in args { if arg == "-v" || arg == "version" || arg == "--version" {
if VERSION_ARGS.contains(&arg.deref()) {
print_version(); print_version();
return true; return true;
} }