@@ -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