mirror of
https://github.com/SinTan1729/movie-rename.git
synced 2024-12-26 12:18:37 -06:00
Add help
This commit is contained in:
parent
89135740a8
commit
3cfe9de455
1 changed files with 24 additions and 3 deletions
27
src/main.rs
27
src/main.rs
|
@ -1,5 +1,5 @@
|
||||||
use load_file::{self, load_str};
|
use load_file::{self, load_str};
|
||||||
use std::{env, fmt, fs};
|
use std::{env, fmt, fs, process::exit};
|
||||||
use tmdb::{model::*, themoviedb::*};
|
use tmdb::{model::*, themoviedb::*};
|
||||||
use torrent_name_parser::Metadata;
|
use torrent_name_parser::Metadata;
|
||||||
use youchoose;
|
use youchoose;
|
||||||
|
@ -43,14 +43,35 @@ fn main() {
|
||||||
let mut args = env::args();
|
let mut args = env::args();
|
||||||
args.next();
|
args.next();
|
||||||
let filenames: Vec<String> = args.collect();
|
let filenames: Vec<String> = args.collect();
|
||||||
|
|
||||||
|
if filenames.contains(&"--help".to_string()) {
|
||||||
|
println!("The expected syntax is:");
|
||||||
|
println!("movie_rename <filename(s)> [--dry-run]");
|
||||||
|
println!(
|
||||||
|
"There needs to be a config file names movie_rename.conf in your $XDG_CONFIG_HOME."
|
||||||
|
);
|
||||||
|
println!("It should consist of two lines. The first line should have your TMDb API key.");
|
||||||
|
println!("The second line should have a pattern, that will be used for the rename.");
|
||||||
|
println!("In the pattern, the variables need to be enclosed in {{}}, the supported variables are `title`, `year` and `director`.");
|
||||||
|
println!(
|
||||||
|
"Extension is always kept. Default pattern is `{{title}} ({{year}}) - {{director}}`"
|
||||||
|
);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
let mut config_file = env::var("XDG_CONFIG_HOME").unwrap_or("$HOME".to_string());
|
let mut config_file = env::var("XDG_CONFIG_HOME").unwrap_or("$HOME".to_string());
|
||||||
if config_file == String::from("$HOME") {
|
if config_file == String::from("$HOME") {
|
||||||
config_file = env::var("$HOME").unwrap();
|
config_file = env::var("$HOME").unwrap();
|
||||||
}
|
}
|
||||||
config_file.push_str("/movie_rename.conf");
|
config_file.push_str("/movie_rename.conf");
|
||||||
let mut config = load_str!(config_file.as_str()).lines();
|
let mut config = load_str!(config_file.as_str()).lines();
|
||||||
let api_key = config.next().unwrap();
|
let api_key = config.next().unwrap_or("");
|
||||||
let pattern = config.next().unwrap();
|
let pattern = config.next().unwrap_or("{title} ({year}) - {director}");
|
||||||
|
|
||||||
|
if api_key == "" {
|
||||||
|
eprintln!("Error reading the config file. Pass --help to see help.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
let tmdb = TMDb {
|
let tmdb = TMDb {
|
||||||
api_key: api_key,
|
api_key: api_key,
|
||||||
|
|
Loading…
Reference in a new issue