From 26eb446de824ab70d41d06863ea0470dbe237ad8 Mon Sep 17 00:00:00 2001
From: SinTan1729 <sayantan.santra689@gmail.com>
Date: Sat, 10 Dec 2022 18:39:33 -0600
Subject: [PATCH] Improved arguments handling

---
 Cargo.lock       |  2 +-
 Cargo.toml       |  2 +-
 README.md        |  8 ++++++--
 movie-rename.1   |  5 ++++-
 src/functions.rs | 18 +++++++++++++-----
 src/main.rs      |  2 +-
 6 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index f1acaed..1e13527 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -738,7 +738,7 @@ dependencies = [
 
 [[package]]
 name = "movie-rename"
-version = "1.2.0"
+version = "1.2.1"
 dependencies = [
  "inquire",
  "load_file",
diff --git a/Cargo.toml b/Cargo.toml
index 4dd02b0..ab655b3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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
diff --git a/README.md b/README.md
index 8b2a904..72957b4 100644
--- a/README.md
+++ b/README.md
@@ -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.
\ No newline at end of file
diff --git a/movie-rename.1 b/movie-rename.1
index d4e8c1c..ba2b88c 100644
--- a/movie-rename.1
+++ b/movie-rename.1
@@ -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.
diff --git a/src/functions.rs b/src/functions.rs
index 7bddf77..a2d7248 100644
--- a/src/functions.rs
+++ b/src/functions.rs
@@ -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("-") {
diff --git a/src/main.rs b/src/main.rs
index 9499ac6..fd9c4a0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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}");