Skip to content

Commit

Permalink
quark: Implement minimal CLI and init run sub command
Browse files Browse the repository at this point in the history
Signed-off-by: Malo Polese <[email protected]>
  • Loading branch information
MaloPolese committed Apr 3, 2022
1 parent f507411 commit 814d42e
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

.idea
*.tar.gz
.vscode
ctr-bundle
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "quark"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "3.0.5", features = ["derive"] }
46 changes: 46 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
mod run;

use crate::cli::run::RunCommand;
use clap::{Parser, Subcommand};

#[derive(Debug)]
pub enum Error {}

pub type Result<T> = std::result::Result<T, Error>;

pub trait Handler {
fn handler(&self) -> Result<()>;
}

/// Create a cli for quark
#[derive(Parser, Debug)]
#[clap(version, author)]
pub struct Cli {
#[clap(subcommand)]
pub(crate) command: Command,
}

impl Cli {
/// Return the command used in the cli.
pub fn command(self) -> Box<dyn Handler> {
match self.command {
Command::Run(cmd) => Box::new(cmd),
}
}
}

/// The enumeration of our commands.
///
/// Each of our commands should be listed in this enumeration with the following format :
/// CommandName(CommandHandler)
///
/// Example:
///
/// You want to add the `list` command:
///
/// List(ListCommand)
#[derive(Subcommand, Debug)]
pub enum Command {
/// Run a quardle
Run(RunCommand),
}
24 changes: 24 additions & 0 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use clap::Args;

use super::{Handler, Result};

/// Arguments for `RunCommand`
///
/// Usage :
/// `quark run --quardle <QUARDLE> --output <OUTPUT>`
#[derive(Debug, Args)]
pub struct RunCommand {
#[clap(short, long)]
quardle: String,

#[clap(short, long)]
output: String,
}

/// Method that will be called when the command is executed.
impl Handler for RunCommand {
fn handler(&self) -> Result<()> {
// TODO
Ok(())
}
}
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use clap::StructOpt;
use cli::{Cli, Result};

mod cli;

fn main() -> Result<()> {
let cli: Cli = Cli::parse();

cli.command().handler()?;

Ok(())
}

0 comments on commit 814d42e

Please sign in to comment.