cargo_leptos/config/
cli.rs1use 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,
9 Server,
11}
12
13#[derive(Debug, Clone, Parser, PartialEq, Default)]
14pub struct Opts {
15 #[arg(short, long)]
17 pub release: bool,
18
19 #[arg(short = 'P', long)]
21 pub precompress: bool,
22
23 #[arg(long)]
25 pub hot_reload: bool,
26
27 #[arg(short, long)]
29 pub project: Option<String>,
30
31 #[arg(long)]
33 pub features: Vec<String>,
34
35 #[arg(long)]
37 pub lib_features: Vec<String>,
38
39 #[arg(long)]
41 pub lib_cargo_args: Option<Vec<String>>,
42
43 #[arg(long)]
45 pub bin_features: Vec<String>,
46
47 #[arg(long)]
49 pub bin_cargo_args: Option<Vec<String>>,
50
51 #[arg(long)]
53 pub wasm_debug: bool,
54
55 #[arg(short, action = clap::ArgAction::Count)]
57 pub verbose: u8,
58
59 #[arg(long, default_value = "true", value_parser=clap::builder::BoolishValueParser::new(), action = clap::ArgAction::Set)]
61 pub js_minify: bool,
62}
63
64#[derive(Debug, Clone, Parser, PartialEq, Default)]
65pub struct BinOpts {
66 #[command(flatten)]
67 opts: Opts,
68
69 #[arg(trailing_var_arg = true)]
70 bin_args: Vec<String>,
71}
72
73#[derive(Debug, Parser)]
74#[clap(version)]
75pub struct Cli {
76 #[arg(long)]
78 pub manifest_path: Option<Utf8PathBuf>,
79
80 #[arg(long)]
82 pub log: Vec<Log>,
83
84 #[command(subcommand)]
85 pub command: Commands,
86}
87
88impl Cli {
89 pub fn opts(&self) -> Option<Opts> {
90 match &self.command {
91 Commands::New(_) => None,
92 Commands::Serve(bin_opts) | Commands::Watch(bin_opts) => Some(bin_opts.opts.clone()),
93 Commands::Build(opts) | Commands::Test(opts) | Commands::EndToEnd(opts) => {
94 Some(opts.clone())
95 }
96 }
97 }
98
99 pub fn opts_mut(&mut self) -> Option<&mut Opts> {
100 match &mut self.command {
101 Commands::New(_) => None,
102 Commands::Serve(bin_opts) | Commands::Watch(bin_opts) => Some(&mut bin_opts.opts),
103 Commands::Build(opts) | Commands::Test(opts) | Commands::EndToEnd(opts) => Some(opts),
104 }
105 }
106
107 pub fn bin_args(&self) -> Option<&[String]> {
108 match &self.command {
109 Commands::Serve(bin_opts) | Commands::Watch(bin_opts) => {
110 Some(bin_opts.bin_args.as_ref())
111 }
112 _ => None,
113 }
114 }
115}
116
117#[derive(Debug, Subcommand, PartialEq)]
118pub enum Commands {
119 Build(Opts),
121 Test(Opts),
123 EndToEnd(Opts),
125 Serve(BinOpts),
127 Watch(BinOpts),
129 New(NewCommand),
131}