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"
|
||||||
|
25
src/main.rs
25
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,10 +8,32 @@ 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();
|
||||||
|
|
||||||
|
// initialize the clap CLI
|
||||||
|
let cli = Cli::parse();
|
||||||
|
|
||||||
|
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
|
// create and initialize our config and repository objects
|
||||||
let c: Config = settings::load_config();
|
let c: Config = settings::load_config();
|
||||||
let r: Repository = Repository::new(&shellexpand::tilde(&c.get_string("transcoder.repository").unwrap()));
|
let r: Repository = Repository::new(&shellexpand::tilde(&c.get_string("transcoder.repository").unwrap()));
|
||||||
@ -18,4 +41,6 @@ fn main() {
|
|||||||
// create and start the video transcoder object
|
// create and start the video transcoder object
|
||||||
let t: Transcoder = Transcoder::new(c, r);
|
let t: Transcoder = Transcoder::new(c, r);
|
||||||
t.start();
|
t.start();
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user