-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
quark: Implement minimal CLI and init
run
sub command
Signed-off-by: Malo Polese <[email protected]>
- Loading branch information
1 parent
f507411
commit 814d42e
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |