-
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.
Signed-off-by: Malo Polese <[email protected]>
- Loading branch information
1 parent
f507411
commit 915d73b
Showing
6 changed files
with
148 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,29 @@ | ||
use clap::Args; | ||
|
||
use super::{Handler, Result}; | ||
|
||
/// Arguments for `BuildCommand` | ||
/// | ||
/// Usage : | ||
/// `quark build --image <IMAGE>` | ||
#[derive(Debug, Args)] | ||
pub struct BuildCommand { | ||
/// The name of the generated quardle, with the suffix `.qrk` | ||
#[clap(short, long)] | ||
quardle: String, | ||
|
||
/// Indicates wether or not the container image is bundled into the initramfs image | ||
#[clap(short, long)] | ||
offline: bool, | ||
|
||
/// Overrides the default kernel command line | ||
#[clap(short, long)] | ||
kernel_cmd: Option<String>, | ||
} | ||
|
||
/// Method that will be called when the command is executed. | ||
impl Handler for BuildCommand { | ||
fn handler(&self) -> Result<()> { | ||
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,59 @@ | ||
mod build; | ||
mod run; | ||
|
||
use crate::cli::build::BuildCommand; | ||
use crate::cli::run::RunCommand; | ||
use clap::{Parser, Subcommand}; | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
OpenFile(std::io::Error), | ||
} | ||
|
||
impl From<std::io::Error> for Error { | ||
fn from(error: std::io::Error) -> Self { | ||
Self::OpenFile(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), | ||
Command::Build(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), | ||
/// Build a quardle | ||
Build(BuildCommand), | ||
} |
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 super::{Handler, Result}; | ||
use clap::Args; | ||
|
||
/// Arguments for `RunCommand` | ||
/// | ||
/// Usage : | ||
/// `quark run --quardle <QUARDLE> --output <OUTPUT>` | ||
#[derive(Debug, Args)] | ||
pub struct RunCommand { | ||
/// Location of the quardle | ||
#[clap(short, long)] | ||
quardle: String, | ||
|
||
/// Folder containing the files generated by the quarks necessary to work | ||
#[clap(short, long)] | ||
output: String, | ||
} | ||
|
||
/// Method that will be called when the command is executed. | ||
impl Handler for RunCommand { | ||
fn handler(&self) -> Result<()> { | ||
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(()) | ||
} |