Downgraded version of Clap module; started work on a configure subcommand to help users set up their service
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-10-21 19:21:52 -04:00
parent 327ec9c62f
commit 0b327f304e
4 changed files with 37 additions and 5 deletions

View File

@ -8,7 +8,7 @@ license = "BSD 2-Clause"
authors = ["Gregory Ballantine <gballantine@bitgoblin.tech>"]
[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"

24
src/cmd/core.rs Normal file
View File

@ -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();
}

1
src/cmd/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod core;

View File

@ -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<Commands>,
}
#[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 => {