Added Clap module for more advanced CLI command/argument handling
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
21740a63c1
commit
327ec9c62f
@ -8,6 +8,7 @@ license = "BSD 2-Clause"
|
|||||||
authors = ["Gregory Ballantine <gballantine@bitgoblin.tech>"]
|
authors = ["Gregory Ballantine <gballantine@bitgoblin.tech>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
clap = { version = "4.0", features = ['derive'] }
|
||||||
config = { version = "0.13", features = ['toml'] }
|
config = { version = "0.13", features = ['toml'] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
log4rs = "1.1"
|
log4rs = "1.1"
|
||||||
|
37
src/main.rs
37
src/main.rs
@ -1,3 +1,4 @@
|
|||||||
|
use clap::{Parser, Subcommand};
|
||||||
use log4rs;
|
use log4rs;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use transcoder::repository::Repository;
|
use transcoder::repository::Repository;
|
||||||
@ -7,15 +8,39 @@ mod settings;
|
|||||||
mod transcoder;
|
mod transcoder;
|
||||||
mod util;
|
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() {
|
fn main() {
|
||||||
// initialize the log4rs logger
|
// initialize the log4rs logger
|
||||||
log4rs::init_file("./log4rs.yaml", Default::default()).unwrap();
|
log4rs::init_file("./log4rs.yaml", Default::default()).unwrap();
|
||||||
|
|
||||||
// create and initialize our config and repository objects
|
// initialize the clap CLI
|
||||||
let c: Config = settings::load_config();
|
let cli = Cli::parse();
|
||||||
let r: Repository = Repository::new(&shellexpand::tilde(&c.get_string("transcoder.repository").unwrap()));
|
|
||||||
|
|
||||||
// create and start the video transcoder object
|
match &cli.command {
|
||||||
let t: Transcoder = Transcoder::new(c, r);
|
// sub-commands will be handled here
|
||||||
t.start();
|
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();
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user