forked from Cutieguwu/raven
Initial Commit.
This commit is contained in:
59
src/cli.rs
Normal file
59
src/cli.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use clap::{ArgAction, Parser, Subcommand};
|
||||
|
||||
pub static CONFIG: LazyLock<Args> = LazyLock::new(|| Args::parse());
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Args {
|
||||
#[command(subcommand)]
|
||||
pub command: Command,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum Command {
|
||||
/// Create a new raven project
|
||||
New { project_name: String },
|
||||
/// Create a new raven project in an existing directory
|
||||
Init,
|
||||
/// Compile the current project
|
||||
Build,
|
||||
/// Run the current project
|
||||
#[command(arg_required_else_help = true)]
|
||||
Run {
|
||||
#[arg(required = true)]
|
||||
entry_point: String,
|
||||
|
||||
#[clap(flatten)]
|
||||
assertions: Assertions,
|
||||
},
|
||||
/// Run the tests
|
||||
Test {
|
||||
#[clap(flatten)]
|
||||
assertions: Assertions,
|
||||
},
|
||||
/// Remove the target directory
|
||||
Clean,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn depends_on_nest(&self) -> bool {
|
||||
match self {
|
||||
Self::Init | Self::New { .. } => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, clap::Args)]
|
||||
pub struct Assertions {
|
||||
/// Disable assertions.
|
||||
#[arg(short, long = "no-assert", action = ArgAction::SetFalse)]
|
||||
disable_assert: bool,
|
||||
}
|
||||
|
||||
impl Into<bool> for &Assertions {
|
||||
fn into(self) -> bool {
|
||||
!self.disable_assert
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user