-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
242 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::path::PathBuf; | ||
|
||
use clap::{arg, command, value_parser, Command}; | ||
use indoc::indoc; | ||
|
||
use crate::utils::threads; | ||
|
||
pub fn cli() -> Command { | ||
command!() | ||
.arg_required_else_help(true) | ||
.arg( | ||
arg!([FILES] ... "Input file(s) to process") | ||
.long_help(indoc! {"Input file(s) to process | ||
If the file path contains spaces, enclose the path with double quotation marks on both sides."}) | ||
.value_parser(value_parser!(PathBuf)) | ||
.global(true) | ||
.last(true), | ||
) | ||
.arg( | ||
arg!(-d --directory <DIR> "The directory to write output file(s) to") | ||
.long_help(indoc! {"The directory to write output file(s) to | ||
Output files will be written without preserving the folder structure unless the --recursive flag is used."}) | ||
.value_parser(value_parser!(PathBuf)), | ||
) | ||
.arg( | ||
arg!(-r --recursive "Preserves the folder structure when writing output file(s)") | ||
.long_help(indoc! {"Preserves the folder structure when writing output file(s). | ||
This option should be used in conjunction with the --directory option."}) | ||
.requires("directory"), | ||
) | ||
.arg( | ||
arg!(-s --suffix [SUFFIX] "Adds the '@suffix' to the names of output file(s)") | ||
.long_help(indoc! {"Adds the '@suffix' to the names of output file(s) | ||
When '2x' is provided as the value, the resulting files will be renamed with the '@2x' suffix. | ||
For example, a file named 'file.jpeg' will become '[email protected]'. | ||
If no suffix is provided, the default updated suffix '@updated' will be added to the resulting files."}) | ||
.default_missing_value("updated"), | ||
) | ||
.arg( | ||
arg!(-b --backup "Adds the '@backup' to the names of input file(s)") | ||
) | ||
.arg( | ||
arg!(-t --threads <NUM> "The number of threads for concurrent processing") | ||
.long_help(indoc! {"The number of threads for concurrent processing | ||
Usage of multiple threads can speed up the execution of tasks, especially on multi-core processors. | ||
By default, the number of available threads is utilized"}) | ||
.value_parser(value_parser!(u8).range(1..=threads::num_threads() as i64)), | ||
) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
fn main() {} | ||
use cli::cli; | ||
|
||
mod cli; | ||
mod utils; | ||
|
||
fn main() { | ||
let matches = cli().get_matches(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod threads; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use std::{num::NonZeroUsize, thread}; | ||
|
||
pub fn num_threads() -> usize { | ||
thread::available_parallelism() | ||
.unwrap_or(NonZeroUsize::new(4).unwrap()) | ||
.get() | ||
} |