summaryrefslogtreecommitdiff
path: root/cli/args/flags.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-08-08 17:54:39 +0100
committerGitHub <noreply@github.com>2024-08-08 16:54:39 +0000
commitffe1bfd54c2065fe718872f67e19e8a863c0bf22 (patch)
treecf315d0c24fd72afd7957622008e7c1893d68ab8 /cli/args/flags.rs
parent3f692bed0a62de79895ea3373b9004fd6a542035 (diff)
feat: `deno init --serve` (#24897)
This commit adds "--serve" flag to "deno init" subcommand, that provides a template for quick starting a project using "deno serve". --------- Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r--cli/args/flags.rs38
1 files changed, 33 insertions, 5 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 1053e8f3f..e28ce549b 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -214,6 +214,7 @@ impl FmtFlags {
pub struct InitFlags {
pub dir: Option<String>,
pub lib: bool,
+ pub serve: bool,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -2121,6 +2122,14 @@ fn init_subcommand() -> Command {
.required(false)
.action(ArgAction::SetTrue),
)
+ .arg(
+ Arg::new("serve")
+ .long("serve")
+ .long_help("Generate an example project for `deno serve`")
+ .conflicts_with("lib")
+ .required(false)
+ .action(ArgAction::SetTrue),
+ )
})
}
@@ -4174,6 +4183,7 @@ fn init_parse(flags: &mut Flags, matches: &mut ArgMatches) {
flags.subcommand = DenoSubcommand::Init(InitFlags {
dir: matches.remove_one::<String>("dir"),
lib: matches.get_flag("lib"),
+ serve: matches.get_flag("serve"),
});
}
@@ -10026,7 +10036,8 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Init(InitFlags {
dir: None,
- lib: false
+ lib: false,
+ serve: false,
}),
..Flags::default()
}
@@ -10038,7 +10049,8 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Init(InitFlags {
dir: Some(String::from("foo")),
- lib: false
+ lib: false,
+ serve: false,
}),
..Flags::default()
}
@@ -10050,7 +10062,8 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Init(InitFlags {
dir: None,
- lib: false
+ lib: false,
+ serve: false,
}),
log_level: Some(Level::Error),
..Flags::default()
@@ -10063,7 +10076,21 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Init(InitFlags {
dir: None,
- lib: true
+ lib: true,
+ serve: false,
+ }),
+ ..Flags::default()
+ }
+ );
+
+ let r = flags_from_vec(svec!["deno", "init", "--serve"]);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ subcommand: DenoSubcommand::Init(InitFlags {
+ dir: None,
+ lib: false,
+ serve: true,
}),
..Flags::default()
}
@@ -10075,7 +10102,8 @@ mod tests {
Flags {
subcommand: DenoSubcommand::Init(InitFlags {
dir: Some(String::from("foo")),
- lib: true
+ lib: true,
+ serve: false,
}),
..Flags::default()
}