From f042c39180c1b345de8e7b5f0dfae5d0a49b161f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 19 Aug 2024 14:56:53 +0200 Subject: [PATCH] add free arg --- cli/args/flags.rs | 33 ++++++++++++++++++++++++++------- cli/tools/upgrade.rs | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 8a1732b2f7..86b2d95368 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -3019,8 +3019,23 @@ The declaration file could be saved and used for typing information.", fn upgrade_subcommand() -> Command { command( "upgrade", - "Upgrade deno executable to the given version. -Defaults to latest. + color_print::cstr!("Upgrade deno executable to the given version. + +Latest + + deno upgrade + +Specific version + + deno upgrade 1.45.0 + deno upgrade 1.46.0-rc.1 + deno upgrade 9bc2dd29ad6ba334fd57a20114e367d3c04763d4 + +Channel + + deno upgrade stable + deno upgrade rc + deno upgrade canary The version is downloaded from https://github.com/denoland/deno/releases @@ -3028,7 +3043,7 @@ and is used to replace the current executable. If you want to not replace the current Deno executable but instead download an update to a different location, use the --output flag: - deno upgrade --output $HOME/my_deno", + deno upgrade --output $HOME/my_deno"), UnstableArgsConfig::None, ) .hide(cfg!(not(feature = "upgrade"))) @@ -3038,7 +3053,8 @@ update to a different location, use the --output flag: Arg::new("version") .long("version") .help("The version to upgrade to") - .help_heading(UPGRADE_HEADING), + .help_heading(UPGRADE_HEADING)// NOTE(bartlomieju): pre-v1.46 compat + .hide(true), ) .arg( Arg::new("output") @@ -3068,7 +3084,8 @@ update to a different location, use the --output flag: .long("canary") .help("Upgrade to canary builds") .action(ArgAction::SetTrue) - .help_heading(UPGRADE_HEADING), + .help_heading(UPGRADE_HEADING)// NOTE(bartlomieju): pre-v1.46 compat + .hide(true), ) .arg( Arg::new("release-candidate") @@ -3076,11 +3093,13 @@ update to a different location, use the --output flag: .help("Upgrade to a release candidate") .conflicts_with_all(["canary", "version"]) .action(ArgAction::SetTrue) - .help_heading(UPGRADE_HEADING), + .help_heading(UPGRADE_HEADING) + // NOTE(bartlomieju): pre-v1.46 compat + .hide(true), ) .arg( Arg::new("version-or-hash-or-channel") - .help("Version, channel or commit hash") + .help(color_print::cstr!("Version (v1.46.0), channel (rc, canary) or commit hash (9bc2dd29ad6ba334fd57a20114e367d3c04763d4)")) .value_name("VERSION") .action(ArgAction::Append) .trailing_var_arg(true), diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index f25f5322b1..85ea973b73 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -547,7 +547,7 @@ pub async fn upgrade( Ok(()) } -#[derive(Debug)] +#[derive(Debug, PartialEq)] enum RequestedVersion { Latest(ReleaseChannel), SpecificVersion(ReleaseChannel, String), @@ -1048,6 +1048,39 @@ mod test { use super::*; + #[test] + fn test_requested_version() { + let mut upgrade_flags = UpgradeFlags { + dry_run: false, + force: false, + release_candidate: false, + canary: false, + version: None, + output: None, + version_or_hash_or_channel: None, + }; + + let req_ver = + RequestedVersion::from_upgrade_flags(upgrade_flags.clone()).unwrap(); + assert_eq!(req_ver, RequestedVersion::Latest(ReleaseChannel::Stable)); + + let req_ver = + RequestedVersion::from_upgrade_flags(upgrade_flags.clone()).unwrap(); + assert_eq!(req_ver, RequestedVersion::Latest(ReleaseChannel::Stable)); + + let req_ver = + RequestedVersion::from_upgrade_flags(upgrade_flags.clone()).unwrap(); + assert_eq!(req_ver, RequestedVersion::Latest(ReleaseChannel::Stable)); + + let req_ver = + RequestedVersion::from_upgrade_flags(upgrade_flags.clone()).unwrap(); + assert_eq!(req_ver, RequestedVersion::Latest(ReleaseChannel::Stable)); + + let req_ver = + RequestedVersion::from_upgrade_flags(upgrade_flags.clone()).unwrap(); + assert_eq!(req_ver, RequestedVersion::Latest(ReleaseChannel::Stable)); + } + #[test] fn test_parse_upgrade_check_file() { // NOTE(bartlomieju): pre-1.46 format