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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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, axum)
Server,
}
#[derive(Debug, Clone, Parser, PartialEq, Default)]
pub struct Opts {
/// Build artifacts in release mode, with optimizations.
#[arg(short, long)]
pub release: bool,
/// Precompress static assets with gzip and brotli. Applies to release builds only.
#[arg(short = 'P', long)]
pub precompress: 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 cargo flags to pass to cargo when compiling the lib target
#[arg(long)]
pub lib_cargo_args: Option<Vec<String>>,
/// The features to use when compiling the bin target
#[arg(long)]
pub bin_features: Vec<String>,
/// The cargo flags to pass to cargo when compiling the bin target
#[arg(long)]
pub bin_cargo_args: Option<Vec<String>>,
/// Include debug information in Wasm output. Includes source maps and DWARF debug info.
#[arg(long)]
pub wasm_debug: bool,
/// Verbosity (none: info, errors & warnings, -v: verbose, -vv: very verbose).
#[arg(short, action = clap::ArgAction::Count)]
pub verbose: u8,
/// Minify javascript assets with swc. Applies to release builds only.
#[arg(long, default_value = "true", value_parser=clap::builder::BoolishValueParser::new(), action = clap::ArgAction::Set)]
pub js_minify: bool,
/// Split WASM binary based on #[lazy] macros.
#[arg(long)]
pub split: bool,
}
#[derive(Debug, Clone, Parser, PartialEq, Default)]
pub struct BinOpts {
#[command(flatten)]
opts: Opts,
#[arg(trailing_var_arg = true)]
bin_args: Vec<String>,
}
#[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> {
match &self.command {
Commands::New(_) => None,
Commands::Serve(bin_opts) | Commands::Watch(bin_opts) => Some(bin_opts.opts.clone()),
Commands::Build(opts) | Commands::Test(opts) | Commands::EndToEnd(opts) => {
Some(opts.clone())
}
}
}
pub fn opts_mut(&mut self) -> Option<&mut Opts> {
match &mut self.command {
Commands::New(_) => None,
Commands::Serve(bin_opts) | Commands::Watch(bin_opts) => Some(&mut bin_opts.opts),
Commands::Build(opts) | Commands::Test(opts) | Commands::EndToEnd(opts) => Some(opts),
}
}
pub fn bin_args(&self) -> Option<&[String]> {
match &self.command {
Commands::Serve(bin_opts) | Commands::Watch(bin_opts) => {
Some(bin_opts.bin_args.as_ref())
}
_ => None,
}
}
}
#[derive(Debug, Subcommand, PartialEq)]
pub enum Commands {
/// Build the server (feature ssr) and the client (wasm with feature hydrate).
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 hydrate mode.
Serve(BinOpts),
/// Serve and automatically reload when files change.
Watch(BinOpts),
/// Start a wizard for creating a new project (using cargo-generate).
New(NewCommand),
}