diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4248879..da70520 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [lib] name = "reddit_bot_cli" -path = "src/lib/mod.rs" +path = "src/cli-lib/mod.rs" [dependencies] clap = "3.2.8" diff --git a/cli/src/cli-lib/commands.rs b/cli/src/cli-lib/commands.rs new file mode 100644 index 0000000..88ada8e --- /dev/null +++ b/cli/src/cli-lib/commands.rs @@ -0,0 +1,16 @@ +use crate::error::Error; +use std::process::Command; +use execute::Execute; +pub fn create_video() -> Result<(), Error> { + let mut command = Command::new("python"); + command.arg("main.py"); + match command.execute_output() { + Ok(o) => { + println!("{}", String::from_utf8(o.stdout).unwrap()) + }, + Err(e) => { + return Err(Error::ScriptError(e.to_string())) + } + } + Ok(()) +} \ No newline at end of file diff --git a/cli/src/cli-lib/error.rs b/cli/src/cli-lib/error.rs new file mode 100644 index 0000000..53ef3de --- /dev/null +++ b/cli/src/cli-lib/error.rs @@ -0,0 +1,16 @@ + +use clap::Error as ClapError; + + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error("There is an error with the cli: {0}")] + CliError(#[from] ClapError), + #[error("Error while running the script: {0}")] + ScriptError(String), + #[error("Standard Input/Ouput error: {0}")] + IoError(#[from] std::io::Error) +} + + + diff --git a/cli/src/cli-lib/mod.rs b/cli/src/cli-lib/mod.rs new file mode 100644 index 0000000..bdc71f0 --- /dev/null +++ b/cli/src/cli-lib/mod.rs @@ -0,0 +1,31 @@ +use clap::Command; +use commands::create_video; +use error::Error; + +pub mod commands; +pub mod error; + +pub struct Cli; + +impl Cli { + pub fn start() -> Result<(), Error> { + let app = Command::new("reddit-video-maker") + .about("Create Reddit Videos with \u{2728} one command \u{2728}") + .subcommand( + Command::new("create").about("Start the process of creating the video") + ); + let matches = app.clone().get_matches(); + match matches.subcommand() { + Some(("create", _)) => { + create_video()?; + }, + Some(_) => { + app.clone().print_help()?; + } + None => { + app.clone().print_help()?; + } + } + Ok(()) + } +}