Skip to content

Commit 7fc1006

Browse files
committed
no-exec
1 parent a6c522d commit 7fc1006

7 files changed

Lines changed: 43 additions & 27 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "simagef"
33
description = "CLI tool for finding similar images"
4-
version = "1.3.5"
4+
version = "1.3.6"
55
edition = "2021"
66
license = "GPL-3.0-or-later"
77
repository = "https://github.com/gert7/simagef"
@@ -33,6 +33,7 @@ num = "0.4.3"
3333
pixel = ["image-compare"]
3434
avif = ["image/avif-native"]
3535
instrumentation = []
36+
no-exec = []
3637

3738
[dev-dependencies]
3839
pretty_assertions = "1.4.0"

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ subsequent runs in the default mode. Signatures will be stored in your cache
107107
directory in a SQLite database file named `simagef`. You can disable this with
108108
the `--no-database` option.
109109

110+
### Feature flags
111+
112+
- `avif` - Enables AVIF support. Requires [libdav1d](https://github.com/videolan/dav1d).
113+
114+
- `no-exec` - Disables the `exec` option.
115+
116+
- `pixel` - Enables the old pixel algorithm.
117+
110118
## Caveats
111119

112120
- The groups are created using a recursive graph algorithm.

src/cli.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct Cli {
4848
/// The program to launch when the comparisons are finished.
4949
/// The program will be launched for each pair or grouping, one after another.
5050
#[arg(short('e'), long)]
51+
#[cfg(not(feature = "no-exec"))]
5152
pub exec: Option<String>,
5253
/// If set, will only present the matched images in pairs rather than groups.
5354
#[arg(short('p'), long, default_value_t = false)]

src/main.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
2828
use rusqlite::Connection;
2929

3030
use crate::{
31-
cli::Fmt, database::InsertionMessage, formatting::print_fmt, open_image::open_image_path,
31+
cli::Fmt, database::InsertionMessage, formatting::print_fmt, open_image::open_image_path, shared::get_executable,
3232
};
3333

3434
struct SignatureToCompare {
@@ -110,6 +110,7 @@ fn make_groups_and_exec<P>(
110110
.map(|index| name_map[*index].as_ref())
111111
.collect();
112112
print_fmt(&name_group, fmt);
113+
#[cfg(not(feature = "no-exec"))]
113114
if let Some((program, args)) = &executable {
114115
Command::new(program)
115116
.args(args)
@@ -390,6 +391,7 @@ fn spawn_cosine_threads(threshold: f64, task_rx: Receiver<CompareTask>, pair_tx:
390391
fn main_signatures(cli: Cli) {
391392
let db_path = cli
392393
.database_file
394+
.as_ref()
393395
.map(|path| PathBuf::from(path))
394396
.or_else(|| platform_dirs::AppDirs::new(Some("simagef"), false).map(|v| v.cache_dir));
395397

@@ -527,14 +529,7 @@ fn main_signatures(cli: Cli) {
527529

528530
let mut pairings = Vec::new();
529531

530-
let executable = {
531-
cli.exec.as_ref().map(|exec| {
532-
let mut split = exec.split(" ");
533-
let command = split.next().expect("Command for exec not provided");
534-
let rest: Vec<&str> = split.collect();
535-
(command, rest)
536-
})
537-
};
532+
let executable = get_executable(&cli);
538533

539534
while let Ok(pair) = pair_rx.recv() {
540535
// If we use pairs, we execute for each pair right away.
@@ -544,6 +539,7 @@ fn main_signatures(cli: Cli) {
544539
let filename1 = &image1.path;
545540
let filename2 = &image2.path;
546541
print_fmt(&vec![filename1, filename2], cli.format);
542+
#[cfg(not(feature = "no-exec"))]
547543
if let Some((program, args)) = &executable {
548544
Command::new(program)
549545
.args(args)

src/main_image.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use image_compare::BlendInput;
1212

1313
use crate::{
1414
cli::Cli,
15-
open_image::{open_image, resize_as_needed, IBoft, SingleImage},
16-
shared::{make_groups_and_exec, CompareTask, Pairing},
1715
formatting::print_fmt,
16+
open_image::{open_image, resize_as_needed, IBoft, SingleImage},
17+
shared::{get_executable, make_groups_and_exec, CompareTask, Pairing},
1818
};
1919
struct ImageToCompare {
2020
path: String,
@@ -41,7 +41,7 @@ fn image_maker_loop(
4141
Ok(image) => {
4242
let image = resize_as_needed(image, width, height);
4343
tx.send(ImageToCompare {
44-
path: filename,
44+
path: filename.to_string(),
4545
image,
4646
})
4747
.expect("Unable to send image to channel");
@@ -89,12 +89,12 @@ pub fn main_images(cli: Cli) {
8989
exit(1);
9090
}
9191

92-
for arg_filename in cli.files {
92+
for arg_filename in &cli.files {
9393
if arg_filename == "-" {
9494
dash_mode = true;
9595
} else {
9696
filename_tx
97-
.send(arg_filename)
97+
.send(arg_filename.clone())
9898
.expect("Unable to send filename to channel");
9999
}
100100
}
@@ -241,14 +241,7 @@ pub fn main_images(cli: Cli) {
241241

242242
let mut pairings = Vec::new();
243243

244-
let executable = {
245-
cli.exec.as_ref().map(|exec| {
246-
let mut split = exec.split(" ");
247-
let command = split.next().expect("Command for exec not provided");
248-
let rest: Vec<&str> = split.collect();
249-
(command, rest)
250-
})
251-
};
244+
let executable = get_executable(&cli);
252245

253246
// If we use pairs, we execute for each pair right away.
254247
while let Ok(pair) = pair_rx.recv() {
@@ -259,6 +252,7 @@ pub fn main_images(cli: Cli) {
259252
let filename1 = bundle.image_map[pair.index1].path.clone();
260253
let filename2 = bundle.image_map[pair.index2].path.clone();
261254
print_fmt(&vec![&filename1, &filename2], cli.format);
255+
#[cfg(not(feature = "no-exec"))]
262256
if let Some((program, args)) = &executable {
263257
Command::new(program)
264258
.args(args)

src/shared.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::{
33
process::Command,
44
};
55

6+
use crate::cli::Cli;
7+
68
#[derive(Debug)]
79
pub struct CompareTask {
810
pub index1: usize,
@@ -23,11 +25,10 @@ pub fn make_groups_and_exec(
2325
) {
2426
let groups = make_groups(pairings);
2527
for group in groups {
26-
let name_group: Vec<String> = group.iter().map(|index| {
27-
name_map[*index].clone()
28-
}).collect();
28+
let name_group: Vec<String> = group.iter().map(|index| name_map[*index].clone()).collect();
2929
let line = name_group.join(" ");
3030
println!("{}", line);
31+
#[cfg(not(feature = "no-exec"))]
3132
if let Some((program, args)) = &executable {
3233
Command::new(program)
3334
.args(args)
@@ -82,3 +83,18 @@ pub fn make_groups(pairs: Vec<Pairing>) -> Vec<Vec<usize>> {
8283

8384
groups
8485
}
86+
87+
#[cfg(not(feature = "no-exec"))]
88+
pub fn get_executable(cli: &Cli) -> Option<(&str, Vec<&str>)> {
89+
cli.exec.as_ref().map(|exec| {
90+
let mut split = exec.split(" ");
91+
let command = split.next().expect("Command for exec not provided");
92+
let rest: Vec<&str> = split.collect();
93+
(command, rest)
94+
})
95+
}
96+
97+
#[cfg(feature = "no-exec")]
98+
pub fn get_executable(cli: &Cli) -> Option<(&str, Vec<&str>)> {
99+
None
100+
}

0 commit comments

Comments
 (0)