fix: properly act like a cargo subcommand

This commit is contained in:
insects 2025-05-14 18:35:51 +02:00
parent 91f29ec4e7
commit 417bba825c
3 changed files with 31 additions and 2 deletions

11
Cargo.lock generated
View file

@ -160,6 +160,7 @@ version = "0.1.1"
dependencies = [
"axum",
"clap",
"clap-cargo",
"include_dir",
"serde",
"serde_json",
@ -183,6 +184,16 @@ dependencies = [
"clap_derive",
]
[[package]]
name = "clap-cargo"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d546f0e84ff2bfa4da1ce9b54be42285767ba39c688572ca32412a09a73851e5"
dependencies = [
"anstyle",
"clap",
]
[[package]]
name = "clap_builder"
version = "4.5.38"

View file

@ -11,6 +11,7 @@ include = ["/public", "/src"]
[dependencies]
axum = { version = "0.8.4", features = ["macros"] }
clap = { version = "4.5.38", features = ["derive"] }
clap-cargo = "0.15.2"
include_dir = "0.7.4"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"

View file

@ -5,15 +5,32 @@ use tokio::runtime::Builder;
mod server;
pub const CLAP_STYLING: clap::builder::styling::Styles = clap::builder::styling::Styles::styled()
.header(clap_cargo::style::HEADER)
.usage(clap_cargo::style::USAGE)
.literal(clap_cargo::style::LITERAL)
.placeholder(clap_cargo::style::PLACEHOLDER)
.error(clap_cargo::style::ERROR)
.valid(clap_cargo::style::VALID)
.invalid(clap_cargo::style::INVALID);
#[derive(Parser, Debug)]
#[command(version)]
#[command(name = "cargo")]
#[command(bin_name = "cargo")]
#[command(styles = CLAP_STYLING)]
enum Cli {
Spiel(CliArgs),
}
#[derive(clap::Args, Debug)]
#[command(version, about, long_about = None)]
struct CliArgs {
/// Directory of the Cargo project
pub project: Option<PathBuf>,
}
fn main() {
let args = CliArgs::parse();
let Cli::Spiel(args) = Cli::parse();
let runtime = Builder::new_current_thread()
.worker_threads(2)
.enable_io()