1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
use crate::command::NewCommand;
use camino::Utf8PathBuf;
use clap::{Parser, Subcommand, ValueEnum};
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum Log {
/// WASM build (wasm, wasm-opt, walrus)
Wasm,
/// Internal reload and csr server (hyper, salvo)
Server,
}
#[derive(Debug, Clone, Parser, PartialEq, Default)]
pub struct Opts {
/// Build artifacts in release mode, with optimizations.
#[arg(short, long)]
pub release: bool,
/// Turn on partial hot-reloading. Requires rust nightly [beta]
#[arg(long)]
pub hot_reload: bool,
/// Which project to use, from a list of projects defined in a workspace
#[arg(short, long)]
pub project: Option<String>,
/// The features to use when compiling all targets
#[arg(long)]
pub features: Vec<String>,
/// The features to use when compiling the lib target
#[arg(long)]
pub lib_features: Vec<String>,
/// The features to use when compiling the bin target
#[arg(long)]
pub bin_features: Vec<String>,
/// Verbosity (none: info, errors & warnings, -v: verbose, --vv: very verbose).
#[arg(short, action = clap::ArgAction::Count)]
pub verbose: u8,
}
#[derive(Debug, Parser)]
#[clap(version)]
pub struct Cli {
/// Path to Cargo.toml.
#[arg(long)]
pub manifest_path: Option<Utf8PathBuf>,
/// Output logs from dependencies (multiple --log accepted).
#[arg(long)]
pub log: Vec<Log>,
#[command(subcommand)]
pub command: Commands,
}
impl Cli {
pub fn opts(&self) -> Option<Opts> {
use Commands::{Build, EndToEnd, New, Serve, Test, Watch};
match &self.command {
New(_) => None,
Build(opts) | Serve(opts) | Test(opts) | EndToEnd(opts) | Watch(opts) => Some(opts.clone()),
}
}
}
#[derive(Debug, Subcommand, PartialEq)]
pub enum Commands {
/// Build the server (feature ssr) and the client (wasm with feature csr).
Build(Opts),
/// Run the cargo tests for app, client and server.
Test(Opts),
/// Start the server and end-2-end tests.
EndToEnd(Opts),
/// Serve. Defaults to web-ssr and web-csr mode.
Serve(Opts),
/// Serve and automatically reload when files change.
Watch(Opts),
/// WIP: Start wizard for creating a new project (using cargo-generate). Ask at Glory discord before using.
New(NewCommand),
}