glory_cli/config/
cli.rs

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