1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use std::path::PathBuf;
use clap::{Parser, ValueEnum};
#[derive(Parser)]
#[command(
about,
author,
version,
after_help = "OUTPUT pattern accepts placeholders that have the format of '{I:P}' where 'I' \
is the index of captured group and 'P' is the padding of digits with `0`. Please refer to \
https://github.com/yaa110/nomino for more information.",
next_display_order = None,
)]
pub struct Cli {
/// Runs in test mode without renaming actual files (dry-run).
#[arg(short, long)]
pub test: bool,
/// Recursively creates all parent directories of '<OUTPUT>' if they are missing.
#[arg(short = 'k', long)]
pub mkdir: bool,
/// Overwrites output files, otherwise, a '_' is prepended to filename.
#[arg(short = 'w', long)]
pub overwrite: bool,
/// Preserves the extension of input files in 'sort' and 'regex' options.
#[arg(short, long)]
pub extension: bool,
/// Sets the working directory.
#[arg(short, long = "dir", value_name = "PATH")]
pub directory: Option<PathBuf>,
/// Optional value to set the maximum of subdirectory depth value in 'regex' mode.
#[arg(long, value_name = "DEPTH")]
pub max_depth: Option<usize>,
/// Optional value to overwrite inferred subdirectory depth value in 'regex' mode.
#[arg(long)]
pub depth: Option<usize>,
/// Stores a JSON map file in '<PATH>' after renaming files.
#[arg(short, long, value_name = "PATH")]
pub generate: Option<PathBuf>,
/// Prints the map table to stdout.
#[arg(short, long)]
pub print: bool,
/// Sets the path of map file to be used for renaming files.
#[arg(short, long, value_name = "PATH")]
pub map: Option<PathBuf>,
/// Sets the order of natural sorting (by name) to rename files using enumerator.
#[arg(short, long, value_name = "ORDER", ignore_case = true)]
pub sort: Option<Order>,
/// Regex pattern (RE2 syntax) to match by filenames.
#[arg(short, long, value_name = "PATTERN", requires = "output")]
pub regex: Option<String>,
/// OUTPUT is the pattern to be used for renaming files, and SOURCE is the optional regex pattern to match by filenames. SOURCE has the same function as -r option.
#[arg(value_name = "[SOURCE] OUTPUT")]
pub output: Vec<String>,
}
impl Cli {
pub fn parse() -> Self {
<Self as Parser>::parse()
}
}
#[derive(Clone, ValueEnum)]
pub enum Order {
/// Sort in ascending order.
Asc,
/// Sort in descending order.
Desc,
}
#[cfg(test)]
mod tests {
#[test]
fn verify_cli() {
use clap::CommandFactory;
super::Cli::command().debug_assert();
}
}