From 0b327f304ec2e4258260e9c8513c45f949850610 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Fri, 21 Oct 2022 19:21:52 -0400 Subject: [PATCH] Downgraded version of Clap module; started work on a configure subcommand to help users set up their service --- Cargo.toml | 2 +- src/cmd/core.rs | 24 ++++++++++++++++++++++++ src/cmd/mod.rs | 1 + src/main.rs | 15 +++++++++++---- 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/cmd/core.rs create mode 100644 src/cmd/mod.rs diff --git a/Cargo.toml b/Cargo.toml index bb2a8ce..c608da6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "BSD 2-Clause" authors = ["Gregory Ballantine "] [dependencies] -clap = { version = "4.0", features = ['derive'] } +clap = { version = "3.2", features = ['derive'] } config = { version = "0.13", features = ['toml'] } log = "0.4" log4rs = "1.1" diff --git a/src/cmd/core.rs b/src/cmd/core.rs new file mode 100644 index 0000000..272672d --- /dev/null +++ b/src/cmd/core.rs @@ -0,0 +1,24 @@ +use std::io; +use std::io::Write; + +pub fn configure_command(config_path: &str) { + let repository_dir = get_user_input("Enter your desired video repository directory path: "); + let interval = get_user_input("Enter how long Zealot should wait in between runs (in minutes): "); + + println!("Updating config file {} with repository path {} and interval {}.", config_path, repository_dir, interval); +} + +fn get_user_input(message: &str) -> String { + // print our message to the user, then flush STDIN so the message is sent + print!("{}", message); + io::stdout().flush().unwrap(); + + // now create our string object and read the input + let mut input = String::new(); + io::stdin() + .read_line(&mut input) + .expect("Failed to get user input"); + + // obviously, return the trimmed result as a String object + return input.trim().to_string(); +} diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs new file mode 100644 index 0000000..5a7ca06 --- /dev/null +++ b/src/cmd/mod.rs @@ -0,0 +1 @@ +pub mod core; diff --git a/src/main.rs b/src/main.rs index 2756268..d19aae9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,24 +4,31 @@ use config::Config; use transcoder::repository::Repository; use transcoder::transcoder::Transcoder; +mod cmd; mod settings; mod transcoder; mod util; #[derive(Parser)] -#[command(author, version, about, long_about = None)] +#[clap(author, version, about, long_about = None)] struct Cli { - #[command(subcommand)] + #[clap(subcommand)] command: Option, } #[derive(Subcommand)] enum Commands { /// displays version info about this program - ToDo {}, + Configure {}, } fn main() { + // set the configuration file path depending on the OS + let mut config_path: &str = "/etc/zealot/config.toml"; + if cfg!(windows) { + config_path = "C:\\Program Files\\Zealot\\config.toml"; + } + // initialize the log4rs logger log4rs::init_file("./log4rs.yaml", Default::default()).unwrap(); @@ -30,7 +37,7 @@ fn main() { match &cli.command { // sub-commands will be handled here - Some(_) => todo!(), + Some(Commands::Configure {}) => cmd::core::configure_command(config_path), // run the main program without any commands None => {