summaryrefslogtreecommitdiff
path: root/cli/args/flags.rs
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-09-04 13:06:16 -0700
committerGitHub <noreply@github.com>2024-09-04 13:06:16 -0700
commitc32d692a8f37c50fd700bb320571f76a107a44c2 (patch)
tree3a94f358db8ea390a35e742495848c4b69288fba /cli/args/flags.rs
parente27a19c02c537626d7874f7521f4e39d6dfad0af (diff)
feat(install): deno install with entrypoint (#25411)
``` deno install --entrypoint one.ts two.ts ``` effectively equivalent to `deno cache`
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r--cli/args/flags.rs52
1 files changed, 45 insertions, 7 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 5ea8b8ecf..9397f2180 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -240,11 +240,18 @@ pub struct InstallFlagsGlobal {
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum InstallKind {
- Local(Option<AddFlags>),
+ Local(InstallFlagsLocal),
Global(InstallFlagsGlobal),
}
#[derive(Clone, Debug, Eq, PartialEq)]
+pub enum InstallFlagsLocal {
+ Add(AddFlags),
+ TopLevel,
+ Entrypoints(Vec<String>),
+}
+
+#[derive(Clone, Debug, Eq, PartialEq)]
pub struct InstallFlags {
pub global: bool,
pub kind: InstallKind,
@@ -2365,10 +2372,12 @@ fn install_subcommand() -> Command {
Add dependencies to the local project's configuration (<p(245)>deno.json / package.json</>) and installs them
in the package cache. If no dependency is specified, installs all dependencies listed in the config file.
+If the <p(245)>--entrypoint</> flag is passed, installs the dependencies of the specified entrypoint(s).
<p(245)>deno install</>
<p(245)>deno install @std/bytes</>
<p(245)>deno install npm:chalk</>
+ <p(245)>deno install --entrypoint entry1.ts entry2.ts</>
<g>Global installation</>
@@ -2405,6 +2414,7 @@ These must be added to the path manually if required."), UnstableArgsConfig::Res
.arg(
Arg::new("cmd")
.required_if_eq("global", "true")
+ .required_if_eq("entrypoint", "true")
.num_args(1..)
.value_hint(ValueHint::FilePath),
)
@@ -2412,17 +2422,20 @@ These must be added to the path manually if required."), UnstableArgsConfig::Res
Arg::new("name")
.long("name")
.short('n')
+ .requires("global")
.help("Executable file name"),
)
.arg(
Arg::new("root")
.long("root")
+ .requires("global")
.help("Installation root")
.value_hint(ValueHint::DirPath),
)
.arg(
Arg::new("force")
.long("force")
+ .requires("global")
.short('f')
.help("Forcefully overwrite existing installation")
.action(ArgAction::SetTrue),
@@ -2434,6 +2447,14 @@ These must be added to the path manually if required."), UnstableArgsConfig::Res
.help("Install a package or script as a globally available executable")
.action(ArgAction::SetTrue),
)
+ .arg(
+ Arg::new("entrypoint")
+ .long("entrypoint")
+ .short('e')
+ .conflicts_with("global")
+ .action(ArgAction::SetTrue)
+ .help("Install dependents of the specified entrypoint(s)"),
+ )
.arg(env_file_arg())
})
}
@@ -4419,15 +4440,32 @@ fn install_parse(flags: &mut Flags, matches: &mut ArgMatches) {
force,
}),
});
- } else {
- let local_flags = matches
- .remove_many("cmd")
- .map(|packages| add_parse_inner(matches, Some(packages)));
- allow_scripts_arg_parse(flags, matches);
+ return;
+ }
+
+ // allow scripts only applies to local install
+ allow_scripts_arg_parse(flags, matches);
+ if matches.get_flag("entrypoint") {
+ let entrypoints = matches.remove_many::<String>("cmd").unwrap_or_default();
+ flags.subcommand = DenoSubcommand::Install(InstallFlags {
+ global,
+ kind: InstallKind::Local(InstallFlagsLocal::Entrypoints(
+ entrypoints.collect(),
+ )),
+ });
+ } else if let Some(add_files) = matches
+ .remove_many("cmd")
+ .map(|packages| add_parse_inner(matches, Some(packages)))
+ {
flags.subcommand = DenoSubcommand::Install(InstallFlags {
global,
- kind: InstallKind::Local(local_flags),
+ kind: InstallKind::Local(InstallFlagsLocal::Add(add_files)),
})
+ } else {
+ flags.subcommand = DenoSubcommand::Install(InstallFlags {
+ global,
+ kind: InstallKind::Local(InstallFlagsLocal::TopLevel),
+ });
}
}