feat: Possible to merge the short flags

This commit is contained in:
Sayantan Santra 2023-12-04 18:27:22 -06:00
parent 16118a8d5a
commit bc0ccd8107
Signed by: SinTan1729
GPG Key ID: EB3E68BFBA25C85F
2 changed files with 25 additions and 12 deletions

View File

@ -31,7 +31,7 @@ sudo make install
- Passing `--directory` or `-d` assumes that the arguments are directory names, which contain exactly one movie and optionally subtitles. - Passing `--directory` or `-d` assumes that the arguments are directory names, which contain exactly one movie and optionally subtitles.
- Passing `--dry-run` or `-n` does a dry tun and only prints out the new names, without actually doing anything. - Passing `--dry-run` or `-n` does a dry tun and only prints out the new names, without actually doing anything.
- Passing `--i-feel-lucky` or `-l` automatically chooses the first option. Useful when you use the program as part of a script. - Passing `--i-feel-lucky` or `-l` automatically chooses the first option. Useful when you use the program as part of a script.
- Passing `-nd` or `-dn` does a dry run in directory mode. - You can join the short flags `-d`, `-n` and `-l` together (e.g. `-dn` or `-dln`).
- Passing `--help` or `-h` shows help and exits. - Passing `--help` or `-h` shows help and exits.
- Passing `--version` or `-v` shows version and exits. - Passing `--version` or `-v` shows version and exits.

View File

@ -234,7 +234,9 @@ pub fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str
); );
println!(" Passing --directory or -d assumes that the arguments are directory names, which contain exactly one movie and optionally subtitles."); println!(" Passing --directory or -d assumes that the arguments are directory names, which contain exactly one movie and optionally subtitles.");
println!(" Passing --dry-run or -n does a dry tun and only prints out the new names, without actually doing anything."); println!(" Passing --dry-run or -n does a dry tun and only prints out the new names, without actually doing anything.");
println!(" Passing -nd or -dn does a dry run in directory mode."); println!(
" You can join the short flags -d, -n and -l together (e.g. -dn or -dln)."
);
println!(" Passing --version or -v shows version and exits."); println!(" Passing --version or -v shows version and exits.");
println!(" Pass --help to get this again."); println!(" Pass --help to get this again.");
exit(0); exit(0);
@ -243,27 +245,38 @@ pub fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str
println!("movie-rename {VERSION}"); println!("movie-rename {VERSION}");
exit(0); exit(0);
} }
"--dry-run" | "-n" => { "--dry-run" => {
println!("Doing a dry run..."); println!("Doing a dry run...");
settings.entry("dry_run").and_modify(|x| *x = true); settings.entry("dry_run").and_modify(|x| *x = true);
} }
"--i-feel-lucky" | "-l" => { "--i-feel-lucky" => {
println!("Choosing the first option automatically..."); println!("Choosing the first option automatically...");
settings.entry("lucky").and_modify(|x| *x = true); settings.entry("lucky").and_modify(|x| *x = true);
} }
"--directory" | "-d" => { "--directory" => {
println!("Running in directory mode..."); println!("Running in directory mode...");
settings.entry("directory").and_modify(|x| *x = true); settings.entry("directory").and_modify(|x| *x = true);
} }
"-nd" | "-dn" => {
println!("Doing a dry run in directory mode...");
settings.entry("dry_run").and_modify(|x| *x = true);
settings.entry("directory").and_modify(|x| *x = true);
}
other => { other => {
if other.starts_with('-') { if other.starts_with('-') {
if !other.starts_with("--") && other.len() < 5 {
// Process short args
if other.contains('l') {
println!("Choosing the first option automatically...");
settings.entry("lucky").and_modify(|x| *x = true);
}
if other.contains('d') {
println!("Running in directory mode...");
settings.entry("directory").and_modify(|x| *x = true);
}
if other.contains('n') {
println!("Doing a dry run...");
settings.entry("dry_run").and_modify(|x| *x = true);
}
} else {
eprintln!("Unknown argument passed: {other}"); eprintln!("Unknown argument passed: {other}");
exit(1); exit(1);
}
} else { } else {
entries.push(arg); entries.push(arg);
} }