From 85b4190e8fada6ac483d6b7dcbf6495e02807d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mikrut?= Date: Wed, 23 Sep 2020 12:17:19 +0200 Subject: [PATCH] Add support for version argument e.g. `czkawka_cli --version` --- README.md | 16 +++++++------ czkawka_cli/src/main.rs | 40 +++++++++++++++++++++----------- czkawka_core/src/empty_folder.rs | 4 ++-- czkawka_core/src/lib.rs | 2 ++ czkawka_gui/src/main.rs | 21 ++++++++++++----- 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index e091620..eec0a3e 100644 --- a/README.md +++ b/README.md @@ -22,19 +22,23 @@ This is my first ever project in Rust so probably a lot of things are written in ## TODO - Comments - a lot of things should be described +- Probably extern argument parser in czkawka-cli could be used - More unit tests +- Debian package - Finding files with debug symbols - Maybe windows support, but this will need some refactoring in code - Translation support -- Add support for fast searching based on checking only first ~1MB of file. +- Add support for fast searching based on checking only first ~1 MB of file. - GTK Gui - Selection of records(don't know how to do this) - Popups - Choosing directories(include, excluded) - - Popup with type type of deleted records + - Popup with type of deleted records + - Add Czkawka name to main window(now is czkawka_gui) - Orbtk GUI - Basic selecting included and excluded folders - - + - Text field to show informations about number of found folders/files + - Simple buttons to delete ## Usage and requirements Rustc 1.46 works fine(not sure about a minimal version) @@ -103,10 +107,8 @@ Duplicate Checker(Version 0.1.0) | App| Idle Ram | Max Operational Ram Usage | |:----------:|:-------------:|:-------------:| | Fslint | | | -| Czkawka CLI Debug | | | Czkawka CLI Release | | -| Czkawka GUI Debug | | -| Czkawka GUI Release | | +| Czkawka GTK GUI Release | | Empty folder finder @@ -114,8 +116,8 @@ Empty folder finder | App| Executing Time | |:----------:|:-------------:| | Fslint | | -| Czkawka CLI Debug | | | Czkawka CLI Release | | +| Czkawka GTK GUI Release | | Differences should be more visible when using slower processor or faster disk. diff --git a/czkawka_cli/src/main.rs b/czkawka_cli/src/main.rs index dc5fb12..1817edb 100644 --- a/czkawka_cli/src/main.rs +++ b/czkawka_cli/src/main.rs @@ -1,14 +1,13 @@ -use czkawka_core::{duplicate, empty_folder}; +use czkawka_core::*; use std::{env, process}; fn main() { // Parse argument - let mut all_arguments: Vec = env::args().collect(); + let all_arguments: Vec = env::args().skip(1).collect(); // Not need to check program name let mut commands_arguments: Vec = Vec::new(); - // println!("{:?}", all_arguments); - - all_arguments.remove(0); // Removing program name from arguments + #[cfg(debug_assertions)] + println!("{:?}", all_arguments); // No arguments, so we print help to allow user to learn more about program if all_arguments.is_empty() { @@ -180,6 +179,10 @@ fn main() { #[cfg(not(debug_assertions))] // This will show too much probably unnecessary data to debug, comment line only if needed ef.print_empty_folders(); } + "--version" | "v" => { + println!("Czkawka CLI {}", CZKAWKA_VERSION); + process::exit(0); + } argum => { println!("FATAL ERROR: \"{}\" argument is not supported, check help for more info.", argum); process::exit(1); @@ -194,9 +197,11 @@ Usage of Czkawka: ## Main arguments: --h / --help - prints help, also works without any arguments - Usage example: - czkawka --help - czkawka + + Usage example: + czkawka --help + czkawka + --d <-i directory_to_search> [-e exclude_directories = ""] [-k excluded_items = "DEFAULT"] [-s min_size = 1024] [-x allowed_extension = ""] [-l type_of_search = "hash"] [-o] [-f file_to_save = "results.txt"] [-delete = "aeo"] - search for duplicates files -i directory_to_search - list of directories which should will be searched like /home/rafal @@ -208,18 +213,25 @@ Usage of Czkawka: -x allowed_extension - list of checked extension, e.g. "jpg,mp4" will allow to check "book.jpg" and "car.mp4" but not roman.png. There are also helpful macros which allow to easy use a typcal extension like IMAGE("jpg,kra,gif,png,bmp,tiff,webp,hdr,svg") or TEXT("txt,doc,docx,odt,rtf") -l type_of_search - allows to use fastest which takes into account only size, and more accurate which check if file contnet is same(hashes). -delete - delete found files, by default remove all except the most oldest one, it can take arguments: aen(All except newest one), aeo(All except oldest one), on(Only one newest), oo(Only one oldest) - Usage example: - czkawka --d -i "/home/rafal/,/home/szczekacz" -e "/home/rafal/Pulpit,/home/rafal/Obrazy" -s 25 -x "7z,rar,IMAGE" -l "size" -delete - czkawka --d -i "/etc/,/mnt/Miecz" -s 1000 -x "VIDEO" -l "hash" -o - czkawka --d -i "/var/" -k "/var/l*b/,/var/lo*,*tmp" - czkawka --d -i "/etc/" -delete "aeo" + + Usage example: + czkawka --d -i "/home/rafal/,/home/szczekacz" -e "/home/rafal/Pulpit,/home/rafal/Obrazy" -s 25 -x "7z,rar,IMAGE" -l "size" -delete + czkawka --d -i "/etc/,/mnt/Miecz" -s 1000 -x "VIDEO" -l "hash" -o + czkawka --d -i "/var/" -k "/var/l*b/,/var/lo*,*tmp" + czkawka --d -i "/etc/" -delete "aeo" + --e <-i directory_to_search> [-e exclude_directories = ""] [-o] [-f file_to_save] [-delete] - option to find and delete empty folders -i directory_to_search - list of directories which should will be searched like /home/rafal -e exclude_directories - list of directories which will be excluded from search. -f file_to_save - saves results to file -delete - delete found empty folders - czkawka --e -i "/home/rafal/rr, /home/gateway" -e "/home/rafal/rr/2" -delete + + Usage example: + czkawka --e -i "/home/rafal/rr, /home/gateway" -e "/home/rafal/rr/2" -delete + + --version / --v - prints program name and version + "### ); } diff --git a/czkawka_core/src/empty_folder.rs b/czkawka_core/src/empty_folder.rs index 33432d9..e4c28a3 100644 --- a/czkawka_core/src/empty_folder.rs +++ b/czkawka_core/src/empty_folder.rs @@ -17,7 +17,7 @@ enum FolderEmptiness { /// Struct assigned to each checked folder with parent path(used to ignore parent if children are not empty) and flag which shows if folder is empty #[derive(Clone)] pub struct FolderEntry { - pub parent_path: Option, + parent_path: Option, // Usable only when finding is_empty: FolderEmptiness, pub modified_date: SystemTime, } @@ -367,7 +367,7 @@ impl EmptyFolder { Common::print_time(start_time, SystemTime::now(), "optimize_directories".to_string()); } - /// Set include dir which needs to be relative, exists, + /// Set include dir which needs to be relative, exists etc. pub fn set_include_directory(&mut self, mut include_directory: String) { let start_time: SystemTime = SystemTime::now(); diff --git a/czkawka_core/src/lib.rs b/czkawka_core/src/lib.rs index b8ba6d8..cadf59e 100644 --- a/czkawka_core/src/lib.rs +++ b/czkawka_core/src/lib.rs @@ -1,3 +1,5 @@ pub mod common; pub mod duplicate; pub mod empty_folder; + +pub const CZKAWKA_VERSION: &str = "0.1.2"; diff --git a/czkawka_gui/src/main.rs b/czkawka_gui/src/main.rs index 6c1c065..40e0b1c 100644 --- a/czkawka_gui/src/main.rs +++ b/czkawka_gui/src/main.rs @@ -1,5 +1,5 @@ #[allow(unused_imports)] -use czkawka_core::{duplicate, empty_folder}; +use czkawka_core::*; use humansize::{file_size_opts as options, FileSize}; extern crate gtk; @@ -13,8 +13,8 @@ use std::cell::RefCell; use std::collections::HashMap; use std::rc::Rc; use std::time::UNIX_EPOCH; +use std::{env, process}; -#[derive(Debug)] #[repr(i32)] enum ColumnsDuplicate { Name = 0, @@ -23,6 +23,18 @@ enum ColumnsDuplicate { } fn main() { + // Check for version check + { + let all_arguments: Vec = env::args().skip(1).collect(); // Not need to check program name + + for i in all_arguments { + if i == "--v" || i == "--version" { + println!("Czkawka CLI {}", CZKAWKA_VERSION); + process::exit(0); + } + } + } + gtk::init().expect("Failed to initialize GTK."); // Loading glade file content and build with it help UI @@ -59,7 +71,6 @@ fn main() { let shared_duplication_state: Rc> = Rc::new(RefCell::new(DuplicateFinder::new())); let shared_empty_folders_state: Rc> = Rc::new(RefCell::new(EmptyFolder::new())); - //////////////////////////////////////////////////////////////////////////////////////////////// // GUI Notepad Buttons @@ -87,7 +98,6 @@ fn main() { for i in notebook_chooser_tool.get_children() { notebook_chooser_tool_children_names.push(i.get_buildable_name().unwrap().to_string()); - println!("{}", i.get_buildable_name().unwrap().to_string()); } // Entry @@ -99,7 +109,6 @@ fn main() { // Set starting information in bottom panel { - info_entry.set_text("Duplicated Files"); // Disable all unused buttons @@ -201,7 +210,7 @@ fn main() { df.set_allowed_extensions("".to_owned()); df.set_min_file_size(match minimal_size_entry.get_text().as_str().parse::() { Ok(t) => t, - Err(_) => 1024 // By default + Err(_) => 1024, // By default }); df.set_check_method(check_method.clone()); df.set_delete_method(duplicate::DeleteMethod::None);