Improved arguments handling

This commit is contained in:
Sayantan Santra 2022-12-10 18:39:33 -06:00
parent 3b76f470cd
commit 26eb446de8
6 changed files with 26 additions and 11 deletions

2
Cargo.lock generated
View file

@ -738,7 +738,7 @@ dependencies = [
[[package]]
name = "movie-rename"
version = "1.2.0"
version = "1.2.1"
dependencies = [
"inquire",
"load_file",

View file

@ -1,6 +1,6 @@
[package]
name = "movie-rename"
version = "1.2.0"
version = "1.2.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -13,11 +13,15 @@ Install from [AUR](https://aur.archlinux.org/packages/movie-rename), my personal
- The expected syntax is:
`movie-rename <filename(s)> [-n|--dry-run] [-d|--directory] [-h|--help] [-v|--version]`
- There needs to be a config file named movie-rename.conf in your $XDG_CONFIG_HOME.
- There needs to be a config file named `config` in the `$XDG_CONFIG_HOME/movie-rename/` directory.
- It should consist of two lines. The first line should have your TMDb API key.
- The second line should have a pattern, that will be used for the rename.
- In the pattern, the variables need to be enclosed in {{}}, the supported variables are `title`, `year` and `director`.
- Default pattern is `{title} ({year}) - {director}`. Extension is always kept.
- Passing `--directory` 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 `-nd` or `-dn` does a dry run in directory mode.
- Passing `--help` or `-h` shows help and exits.
- Passing `--version` or `-v` shows version and exits.
- I plan to add more variables in the future. Support for TV Shows will not be added, since [tvnamer](https://github.com/dbr/tvnamer) does that excellently.

View file

@ -17,13 +17,16 @@ Performs a dry run, without actually renaming anything.
-d, --directory
Runs in directory mode. In this mode, it is assumed that the arguments are directory names, which contain exactly one movie and optionally subtitles.
.TP
-dn, -nd
Performs a dry run in directory mode.
.TP
-h, --help
Print help information.
.TP
-v, --version
Print version information.
.SH CONFIG
There needs to be a config file named movie-rename.conf in your $XDG_CONFIG_HOME.
There needs to be a config file named config in the $XDG_CONFIG_HOME/movie-rename/ directory.
It should consist of two lines.
.sp
The first line should have your TMDb API key.

View file

@ -141,7 +141,7 @@ pub fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str
" movie-rename <filename(s)> [-n|--dry-run] [-d|--directory] [-v|--version]"
);
println!(
" There needs to be a config file names movie-rename.conf in your $XDG_CONFIG_HOME."
" There needs to be a config file named config in the $XDG_CONFIG_HOME/movie-rename/ directory."
);
println!(" It should consist of two lines. The first line should have your TMDb API key.");
println!(
@ -151,10 +151,17 @@ pub fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str
println!(
" Default pattern is `{{title}} ({{year}}) - {{director}}`. Extension is always kept."
);
println!("Passing --directory 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 -nd or -dn does a dry run in directory mode.");
println!(" Passing --version or -v shows version and exits.");
println!(" Pass --help to get this again.");
exit(0);
}
"--version" | "-v" => {
println!("movie-rename {}", VERSION);
exit(0);
}
"--dry-run" | "-n" => {
println!("Doing a dry run...");
settings.entry("dry_run").and_modify(|x| *x = true);
@ -163,9 +170,10 @@ pub fn process_args(mut args: Vec<String>) -> (Vec<String>, HashMap<&'static str
println!("Running in directory mode...");
settings.entry("directory").and_modify(|x| *x = true);
}
"--version" | "-v" => {
println!("movie-rename {}", VERSION);
exit(0);
"-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 => {
if other.starts_with("-") {

View file

@ -20,7 +20,7 @@ fn main() {
config_file = env::var("$HOME").unwrap();
config_file.push_str("/.config");
}
config_file.push_str("/movie-rename.conf");
config_file.push_str("/movie-rename/config");
let mut config = load_str!(config_file.as_str()).lines();
let api_key = config.next().unwrap_or("");
let pattern = config.next().unwrap_or("{title} ({year}) - {director}");