From 66ec0f47d6ebe1822a8b23f80ad9b2e1c9e597de Mon Sep 17 00:00:00 2001 From: William G Underwood <42812654+WGUNDERWOOD@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:54:40 +0000 Subject: [PATCH] Remove duplicate file names when provided --- notes.org | 1 - src/args.rs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/notes.org b/notes.org index ae5c7f6..2ff7dcc 100644 --- a/notes.org +++ b/notes.org @@ -3,7 +3,6 @@ ** TODO Improve build times ** TODO Include man page and shell completion in Nix package ** TODO Add to Nix home-manager with empty config file -** TODO Remove duplicate files from arguments ** TODO Add option for no config file * Options and documentation ** Args struct diff --git a/src/args.rs b/src/args.rs index d77dd4b..fb20417 100644 --- a/src/args.rs +++ b/src/args.rs @@ -128,13 +128,18 @@ impl Args { /// Resolve conflicting arguments pub fn resolve(&mut self, logs: &mut Vec) -> u8 { let mut exit_code = 0; + + // stdin implies print self.print |= self.stdin; + + // Set wrapmin self.wrapmin = if self.wraplen >= 50 { self.wraplen - 10 } else { self.wraplen }; + // Check files are passed if no --stdin if !self.stdin && self.files.is_empty() { record_file_log( logs, @@ -144,6 +149,8 @@ impl Args { ); exit_code = 1; } + + // Check no files are passed if --stdin if self.stdin && !self.files.is_empty() { record_file_log( logs, @@ -153,6 +160,11 @@ impl Args { ); exit_code = 1; } + + // Remove duplicate files + self.files.dedup(); + + // Print arguments and exit if self.arguments { println!("{self}"); std::process::exit(0);