1
0
Fork 0
mirror of synced 2024-04-26 16:52:19 +12:00

Add support for version argument e.g.

`czkawka_cli --version`
This commit is contained in:
Rafał Mikrut 2020-09-23 12:17:19 +02:00
parent ab71ee55ed
commit 85b4190e8f
5 changed files with 54 additions and 29 deletions

View file

@ -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.

View file

@ -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<String> = env::args().collect();
let all_arguments: Vec<String> = env::args().skip(1).collect(); // Not need to check program name
let mut commands_arguments: Vec<String> = 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
"###
);
}

View file

@ -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<String>,
parent_path: Option<String>, // 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();

View file

@ -1,3 +1,5 @@
pub mod common;
pub mod duplicate;
pub mod empty_folder;
pub const CZKAWKA_VERSION: &str = "0.1.2";

View file

@ -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<String> = 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<RefCell<_>> = Rc::new(RefCell::new(DuplicateFinder::new()));
let shared_empty_folders_state: Rc<RefCell<_>> = 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::<u64>() {
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);