Skip to content

Commit 7b60a42

Browse files
committed
address comments
1 parent d6587e6 commit 7b60a42

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

crates/volta-core/src/error/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ To {action} the packages '{name}' and '{version}', please {action} them in separ
789789

790790
let call_to_action = format!(
791791
"To {action} node version '{version}', please run `volta {action} {formatted}`. \
792-
To {action} the package '{version}', please use an explicit version such as '{version}@lts'.",
792+
To {action} the package '{version}', please use an explicit version such as '{version}@latest'.",
793793
action=action,
794794
version=version,
795795
formatted=tool_version("node", version)

crates/volta-core/src/tool/serial.rs

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -90,45 +90,43 @@ impl Spec {
9090
where
9191
T: AsRef<str>,
9292
{
93-
let mut args_iter = args.iter();
94-
95-
// The case we are concerned with here is where we have `<number>`.
96-
// That is, exactly one argument, which is a valid version specifier.
97-
//
98-
// - `volta install node@12` is allowed.
99-
// - `volta install 12` is an error.
100-
// - `volta install lts` is an error.
101-
if let (Some(maybe_version), None) = (args_iter.next(), args_iter.next()) {
102-
if is_version_like(maybe_version.as_ref()) {
103-
return Err(ErrorKind::InvalidInvocationOfBareVersion {
104-
action: action.to_string(),
105-
version: maybe_version.as_ref().to_string(),
93+
let mut args = args.iter();
94+
95+
match (args.next(), args.next(), args.next()) {
96+
(Some(maybe_version), None, None) => {
97+
// The case we are concerned with here is where we have `<number>`.
98+
// That is, exactly one argument, which is a valid version specifier.
99+
//
100+
// - `volta install node@12` is allowed.
101+
// - `volta install 12` is an error.
102+
// - `volta install lts` is an error.
103+
if is_version_like(maybe_version.as_ref()) {
104+
return Err(ErrorKind::InvalidInvocationOfBareVersion {
105+
action: action.to_string(),
106+
version: maybe_version.as_ref().to_string(),
107+
}
108+
.into());
106109
}
107-
.into());
108110
}
109-
}
110-
111-
args_iter = args.iter();
112-
113-
// The case we are concerned with here is where we have `<tool> <number>`.
114-
// This is only interesting if there are exactly two args. Then we care
115-
// whether the two items are a bare name (with no `@version`), followed
116-
// by a valid version specifier (ignoring custom tags). That is:
117-
//
118-
// - `volta install node@lts latest` is allowed.
119-
// - `volta install node latest` is an error.
120-
// - `volta install node latest yarn` is allowed.
121-
if let (Some(name), Some(maybe_version), None) =
122-
(args_iter.next(), args_iter.next(), args_iter.next())
123-
{
124-
if !HAS_VERSION.is_match(name.as_ref()) && is_version_like(maybe_version.as_ref()) {
125-
return Err(ErrorKind::InvalidInvocation {
126-
action: action.to_string(),
127-
name: name.as_ref().to_string(),
128-
version: maybe_version.as_ref().to_string(),
111+
(Some(name), Some(maybe_version), None) => {
112+
// The case we are concerned with here is where we have `<tool> <number>`.
113+
// This is only interesting if there are exactly two args. Then we care
114+
// whether the two items are a bare name (with no `@version`), followed
115+
// by a valid version specifier (ignoring custom tags). That is:
116+
//
117+
// - `volta install node@lts latest` is allowed.
118+
// - `volta install node latest` is an error.
119+
// - `volta install node latest yarn` is allowed.
120+
if !HAS_VERSION.is_match(name.as_ref()) && is_version_like(maybe_version.as_ref()) {
121+
return Err(ErrorKind::InvalidInvocation {
122+
action: action.to_string(),
123+
name: name.as_ref().to_string(),
124+
version: maybe_version.as_ref().to_string(),
125+
}
126+
.into());
129127
}
130-
.into());
131128
}
129+
(_, _, _) => {}
132130
}
133131

134132
Ok(())

0 commit comments

Comments
 (0)