Added Clap module for more advanced CLI command/argument handling
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-10-21 00:16:25 -04:00
parent 21740a63c1
commit 327ec9c62f
2 changed files with 32 additions and 6 deletions

View File

@ -8,6 +8,7 @@ license = "BSD 2-Clause"
authors = ["Gregory Ballantine <gballantine@bitgoblin.tech>"]
[dependencies]
clap = { version = "4.0", features = ['derive'] }
config = { version = "0.13", features = ['toml'] }
log = "0.4"
log4rs = "1.1"

View File

@ -1,3 +1,4 @@
use clap::{Parser, Subcommand};
use log4rs;
use config::Config;
use transcoder::repository::Repository;
@ -7,15 +8,39 @@ mod settings;
mod transcoder;
mod util;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
/// displays version info about this program
ToDo {},
}
fn main() {
// initialize the log4rs logger
log4rs::init_file("./log4rs.yaml", Default::default()).unwrap();
// create and initialize our config and repository objects
let c: Config = settings::load_config();
let r: Repository = Repository::new(&shellexpand::tilde(&c.get_string("transcoder.repository").unwrap()));
// initialize the clap CLI
let cli = Cli::parse();
// create and start the video transcoder object
let t: Transcoder = Transcoder::new(c, r);
t.start();
match &cli.command {
// sub-commands will be handled here
Some(_) => todo!(),
// run the main program without any commands
None => {
// create and initialize our config and repository objects
let c: Config = settings::load_config();
let r: Repository = Repository::new(&shellexpand::tilde(&c.get_string("transcoder.repository").unwrap()));
// create and start the video transcoder object
let t: Transcoder = Transcoder::new(c, r);
t.start();
},
}
}