1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-09 07:39:15 -05:00
This commit is contained in:
Bartek Iwańczuk 2024-08-19 02:13:55 +02:00
parent 0e873eda1d
commit 54e67d52fb
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
2 changed files with 29 additions and 9 deletions

View file

@ -412,6 +412,7 @@ pub struct UpgradeFlags {
pub canary: bool,
pub version: Option<String>,
pub output: Option<String>,
pub version_or_hash_or_channel: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@ -2983,6 +2984,13 @@ update to a different location, use the --output flag:
.conflicts_with_all(["canary", "version"])
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("version-or-hash-or-channel")
.help("Version, channel or commit hash")
.value_name("VERSION")
.action(ArgAction::Append)
.trailing_var_arg(true),
)
.arg(ca_file_arg())
})
}
@ -4668,6 +4676,8 @@ fn upgrade_parse(flags: &mut Flags, matches: &mut ArgMatches) {
let release_candidate = matches.get_flag("release-candidate");
let version = matches.remove_one::<String>("version");
let output = matches.remove_one::<String>("output");
let version_or_hash_or_channel =
matches.remove_one::<String>("version-or-hash-or-channel");
flags.subcommand = DenoSubcommand::Upgrade(UpgradeFlags {
dry_run,
force,
@ -4675,6 +4685,7 @@ fn upgrade_parse(flags: &mut Flags, matches: &mut ArgMatches) {
canary,
version,
output,
version_or_hash_or_channel,
});
}

View file

@ -553,20 +553,29 @@ enum RequestedVersion {
impl RequestedVersion {
fn from_upgrade_flags(upgrade_flags: UpgradeFlags) -> Result<Self, AnyError> {
let is_canary = upgrade_flags.canary;
let is_release_candidate = upgrade_flags.release_candidate;
let Some(passed_version) = upgrade_flags.version else {
let re_hash = lazy_regex::regex!("^[0-9a-f]{40}$");
let channel = if is_canary {
ReleaseChannel::Canary
} else if is_release_candidate {
} else if upgrade_flags.release_candidate {
ReleaseChannel::Rc
} else {
ReleaseChannel::Stable
};
let mut maybe_passed_version = upgrade_flags.version.clone();
if let Some(val) = &upgrade_flags.version_or_hash_or_channel {
if let Ok(channel) = ReleaseChannel::deserialize(&val.to_lowercase()) {
// TODO(bartlomieju): print error if any other flags passed?
return Ok(Self::Latest(channel));
} else {
maybe_passed_version = Some(val.to_string());
}
}
let Some(passed_version) = maybe_passed_version else {
return Ok(Self::Latest(channel));
};
let re_hash = lazy_regex::regex!("^[0-9a-f]{40}$");
let passed_version = passed_version
.strip_prefix('v')
.unwrap_or(&passed_version)