Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference directories in CLI #1364

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/linux_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ jobs:
name: czkawka_cli-${{ runner.os }}
path: target/release/czkawka_cli

- name: Build test version
run: cargo build --profile test --bin czkawka_cli

- name: Linux Regression Test
run: |
wget https://github.com/qarmin/czkawka/releases/download/6.0.0/TestFiles.zip
cd ci_tester
cargo build --release
cd ..

ci_tester/target/release/ci_tester target/release/czkawka_cli
ci_tester/target/release/ci_tester target/debug/czkawka_cli

- name: Prepare files to release
run: |
Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ overflow-checks = true

# Optimize all dependencies except application/workspaces, even in debug builds
[profile.dev.package."*"]
opt-level = 3
opt-level = 3

[profile.test]
debug-assertions = true # Forces to crash when there is duplicated item in cli
overflow-checks = true
opt-level = 3
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Due to the removal image_type from image struct, old cache files are incompatible with new version and should be
regenerated
from scratch(it uses new name)
- Some CLI arguments could change short name, due fixing ambiguous names

### Known regressions

Expand All @@ -15,6 +16,7 @@

- Providing nightly
builds - [#1360](https://github.com/qarmin/czkawka/pull/1360) - https://github.com/qarmin/czkawka/releases/tag/Nightly
- Added finding duplicated options in CLI -[#1364](https://github.com/qarmin/czkawka/pull/1364)

### Core

Expand Down Expand Up @@ -53,6 +55,7 @@
- Added ability to show preview of referenced folders - [#1359](https://github.com/qarmin/czkawka/pull/1359)
- Enable selecting with space and jumping over entries with
arrows and opening with enter - [#1359](https://github.com/qarmin/czkawka/pull/1359)
- Added button to rename files with invalid extension -[#1364](https://github.com/qarmin/czkawka/pull/1364)

### GTK GUI

Expand All @@ -68,6 +71,7 @@
- Fixed and added more input parameters to the application - [#1354](https://github.com/qarmin/czkawka/pull/1354)
- Fixed crash when stopping scan multiple times - [#1355](https://github.com/qarmin/czkawka/pull/1355)
- Print results also in debug build - [#1355](https://github.com/qarmin/czkawka/pull/1355)
- Added support for selecting reference directories -[#1364](https://github.com/qarmin/czkawka/pull/1364)

## Version 7.0.0 - 19.02.2024r

Expand Down
5 changes: 5 additions & 0 deletions ci_tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html


[profile.release]
debug-assertions = true
overflow-checks = true

[dependencies]
state = "0.6.0"
handsome_logger = "0.8.0"
Expand Down
13 changes: 13 additions & 0 deletions ci_tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,25 @@ static COLLECTED_FILES: state::InitCell<CollectedFiles> = state::InitCell::new()
const ATTEMPTS: u32 = 10;
const PRINT_MESSAGES_CZKAWKA: bool = true;

fn test_args() {
let modes = ["dup", "big", "empty-folders", "empty-files", "temp", "image", "symlinks", "broken", "ext", "video", "music"];
for mode in modes {
println!("Testing mode {}", mode);
let _ = fs::remove_dir_all("RandomDirWithoutContent");
fs::create_dir_all("RandomDirWithoutContent").expect("Should not fail in tests");
run_with_good_status(&[CZKAWKA_PATH.get().as_str(), mode, "-d", "RandomDirWithoutContent"], true);
}
}

// App runs - ./ci_tester PATH_TO_CZKAWKA
fn main() {
handsome_logger::init().expect("Should not fail in tests");
let args: Vec<String> = std::env::args().collect();
let path_to_czkawka = args[1].clone();
CZKAWKA_PATH.set(path_to_czkawka);

test_args();
return;
remove_test_dir();
run_with_good_status(&["ls"], false);
unzip_files();
Expand Down
8 changes: 0 additions & 8 deletions czkawka_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ cd ..
cargo build --release --bin czkawka_cli
```

## Limitations

Not all available features in core are available in CLI.

List of not available features:

- Ability to use/choose referenced directories

## LICENSE

MIT
29 changes: 24 additions & 5 deletions czkawka_cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum Commands {
#[clap(
name = "dup",
about = "Finds duplicate files",
after_help = "EXAMPLE:\n czkawka dup -d /home/rafal -e /home/rafal/Obrazy -m 25 -x 7z rar IMAGE -s hash -f results.txt -D aeo"
after_help = "EXAMPLE:\n czkawka dup -d /home/rafal - -e /home/rafal/Obrazy -m 25 -x 7z rar IMAGE -s hash -f results.txt -D aeo"
)]
Duplicates(DuplicatesArgs),
#[clap(
Expand Down Expand Up @@ -88,8 +88,10 @@ pub enum Commands {
pub struct DuplicatesArgs {
#[clap(flatten)]
pub common_cli_items: CommonCliItems,
#[clap(flatten)]
pub reference_directories: ReferenceDirectories,
#[clap(
short = 'p',
short = 'Z',
long,
value_parser = parse_minimal_file_size,
default_value = "257144",
Expand Down Expand Up @@ -198,6 +200,8 @@ pub struct TemporaryArgs {
pub struct SimilarImagesArgs {
#[clap(flatten)]
pub common_cli_items: CommonCliItems,
#[clap(flatten)]
pub reference_directories: ReferenceDirectories,
#[clap(
short,
long,
Expand Down Expand Up @@ -264,6 +268,8 @@ pub struct SameMusicArgs {
#[clap(flatten)]
pub common_cli_items: CommonCliItems,
#[clap(flatten)]
pub reference_directories: ReferenceDirectories,
#[clap(flatten)]
pub delete_method: DMethod,
#[clap(flatten)]
pub dry_run: DryRun,
Expand Down Expand Up @@ -317,7 +323,7 @@ pub struct SameMusicArgs {
)]
pub minimum_segment_duration: f32,
#[clap(
short = 'd',
short = 'Y',
long,
value_parser = parse_maximum_difference,
default_value = "2.0",
Expand Down Expand Up @@ -386,6 +392,8 @@ pub struct SimilarVideosArgs {
#[clap(flatten)]
pub common_cli_items: CommonCliItems,
#[clap(flatten)]
pub reference_directories: ReferenceDirectories,
#[clap(flatten)]
pub delete_method: DMethod,
#[clap(flatten)]
pub allow_hard_links: AllowHardLinks,
Expand Down Expand Up @@ -437,7 +445,7 @@ pub struct CommonCliItems {
long,
required = true,
help = "Directorie(s) to search",
long_help = "List of directorie(s) which will be searched(absolute path)"
long_help = "List of directorie(s) which will be searched(absolute path) - this directories are not set as reference folders"
)]
pub directories: Vec<PathBuf>,
#[clap(
Expand Down Expand Up @@ -495,6 +503,17 @@ pub struct FileToSave {
pub file_to_save: Option<PathBuf>,
}

#[derive(Debug, clap::Args)]
pub struct ReferenceDirectories {
#[clap(
short,
long,
help = "Reference directorie(s) to search",
long_help = "List of directorie(s) which will be searched(absolute path) - this directories are set as reference folders, so will not be visible in the results"
)]
pub reference_directories: Vec<PathBuf>,
}

#[derive(Debug, clap::Args)]
pub struct JsonCompactFileToSave {
#[clap(short = 'C', long, value_name = "json-file-name", help = "Saves the results into the compact json file")]
Expand Down Expand Up @@ -527,7 +546,7 @@ pub struct DryRun {

#[derive(Debug, clap::Args)]
pub struct IgnoreSameSize {
#[clap(short, long, help = "Ignore files with the same size, leaving only one file of each size")]
#[clap(short = 'J', long, help = "Ignore files with the same size, leaving only one file of each size")]
pub ignore_same_size: bool,
}

Expand Down
37 changes: 24 additions & 13 deletions czkawka_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::needless_late_init)]
#![warn(clippy::unwrap_used)]

use std::path::PathBuf;
use std::thread;

use clap::Parser;
Expand Down Expand Up @@ -79,6 +80,7 @@ fn main() {
fn duplicates(duplicates: DuplicatesArgs, stop_receiver: &Receiver<()>, progress_sender: &Sender<ProgressData>) {
let DuplicatesArgs {
common_cli_items,
reference_directories,
minimal_file_size,
maximal_file_size,
minimal_cached_file_size,
Expand All @@ -103,7 +105,7 @@ fn duplicates(duplicates: DuplicatesArgs, stop_receiver: &Receiver<()>, progress
);
let mut item = DuplicateFinder::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, Some(reference_directories.reference_directories.as_ref()));
item.set_minimal_file_size(minimal_file_size);
item.set_maximal_file_size(maximal_file_size);
item.set_delete_method(delete_method.delete_method);
Expand All @@ -119,7 +121,7 @@ fn empty_folders(empty_folders: EmptyFoldersArgs, stop_receiver: &Receiver<()>,

let mut item = EmptyFolder::new();

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_folders {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -141,7 +143,7 @@ fn biggest_files(biggest_files: BiggestFilesArgs, stop_receiver: &Receiver<()>,
let params = BigFileParameters::new(number_of_files, big_files_mode);
let mut item = BigFile::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_files {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -156,7 +158,7 @@ fn empty_files(empty_files: EmptyFilesArgs, stop_receiver: &Receiver<()>, progre

let mut item = EmptyFiles::new();

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_files {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -171,7 +173,7 @@ fn temporary(temporary: TemporaryArgs, stop_receiver: &Receiver<()>, progress_se

let mut item = Temporary::new();

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_files {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -184,6 +186,7 @@ fn temporary(temporary: TemporaryArgs, stop_receiver: &Receiver<()>, progress_se
fn similar_images(similar_images: SimilarImagesArgs, stop_receiver: &Receiver<()>, progress_sender: &Sender<ProgressData>) {
let SimilarImagesArgs {
common_cli_items,
reference_directories,
minimal_file_size,
maximal_file_size,
similarity_preset,
Expand All @@ -207,7 +210,7 @@ fn similar_images(similar_images: SimilarImagesArgs, stop_receiver: &Receiver<()
);
let mut item = SimilarImages::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, Some(reference_directories.reference_directories.as_ref()));
item.set_minimal_file_size(minimal_file_size);
item.set_maximal_file_size(maximal_file_size);
item.set_delete_method(delete_method.delete_method);
Expand All @@ -221,6 +224,7 @@ fn similar_images(similar_images: SimilarImagesArgs, stop_receiver: &Receiver<()
fn same_music(same_music: SameMusicArgs, stop_receiver: &Receiver<()>, progress_sender: &Sender<ProgressData>) {
let SameMusicArgs {
common_cli_items,
reference_directories,
delete_method,
minimal_file_size,
maximal_file_size,
Expand All @@ -243,7 +247,7 @@ fn same_music(same_music: SameMusicArgs, stop_receiver: &Receiver<()>, progress_
);
let mut item = SameMusic::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, Some(reference_directories.reference_directories.as_ref()));
item.set_minimal_file_size(minimal_file_size);
item.set_maximal_file_size(maximal_file_size);
item.set_delete_method(delete_method.delete_method);
Expand All @@ -259,7 +263,7 @@ fn invalid_symlinks(invalid_symlinks: InvalidSymlinksArgs, stop_receiver: &Recei

let mut item = InvalidSymlinks::new();

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_files {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -283,7 +287,7 @@ fn broken_files(broken_files: BrokenFilesArgs, stop_receiver: &Receiver<()>, pro
let params = BrokenFilesParameters::new(checked_type);
let mut item = BrokenFiles::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_files {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -295,6 +299,7 @@ fn broken_files(broken_files: BrokenFilesArgs, stop_receiver: &Receiver<()>, pro

fn similar_videos(similar_videos: SimilarVideosArgs, stop_receiver: &Receiver<()>, progress_sender: &Sender<ProgressData>) {
let SimilarVideosArgs {
reference_directories,
common_cli_items,
tolerance,
minimal_file_size,
Expand All @@ -308,7 +313,7 @@ fn similar_videos(similar_videos: SimilarVideosArgs, stop_receiver: &Receiver<()
let params = SimilarVideosParameters::new(tolerance, ignore_same_size.ignore_same_size, !allow_hard_links.allow_hard_links);
let mut item = SimilarVideos::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, Some(reference_directories.reference_directories.as_ref()));
item.set_minimal_file_size(minimal_file_size);
item.set_maximal_file_size(maximal_file_size);
item.set_delete_method(delete_method.delete_method);
Expand All @@ -325,7 +330,7 @@ fn bad_extensions(bad_extensions: BadExtensionsArgs, stop_receiver: &Receiver<()
let params = BadExtensionsParameters::new();
let mut item = BadExtensions::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);

item.find_bad_extensions_files(Some(stop_receiver), Some(progress_sender));

Expand Down Expand Up @@ -354,13 +359,19 @@ fn save_and_print_results<T: CommonData + PrintResults>(component: &mut T, commo
component.get_text_messages().print_messages();
}

fn set_common_settings<T>(component: &mut T, common_cli_items: &CommonCliItems)
fn set_common_settings<T>(component: &mut T, common_cli_items: &CommonCliItems, reference_directories: Option<&Vec<PathBuf>>)
where
T: CommonData + PrintResults,
{
set_number_of_threads(common_cli_items.thread_number);

component.set_included_directory(common_cli_items.directories.clone());
let mut included_directories = common_cli_items.directories.clone();
if let Some(reference_directories) = reference_directories {
included_directories.extend_from_slice(reference_directories);
component.set_reference_directory(reference_directories.clone());
}

component.set_included_directory(included_directories);
component.set_excluded_directory(common_cli_items.excluded_directories.clone());
component.set_excluded_items(common_cli_items.excluded_items.clone());
component.set_recursive_search(!common_cli_items.not_recursive);
Expand Down
Loading
Loading