@@ -30,14 +30,11 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
30
30
args. get_one :: < String > ( "crate" ) . map ( String :: as_str) ,
31
31
args. get_one :: < String > ( "version" ) . map ( String :: as_str) ,
32
32
) ?;
33
- if version. is_none ( ) {
34
- return Err ( anyhow:: format_err!( "`--version` is required" ) . into ( ) ) ;
35
- }
36
33
37
34
ops:: yank (
38
35
gctx,
39
36
krate. map ( |s| s. to_string ( ) ) ,
40
- version. map ( |s| s . to_string ( ) ) ,
37
+ version. to_string ( ) ,
41
38
args. get_one :: < String > ( "token" ) . cloned ( ) . map ( Secret :: from) ,
42
39
args. registry_or_index ( gctx) ?,
43
40
args. flag ( "undo" ) ,
@@ -46,19 +43,28 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
46
43
}
47
44
48
45
fn resolve_crate < ' k > (
49
- mut krate : Option < & ' k str > ,
50
- mut version : Option < & ' k str > ,
51
- ) -> crate :: CargoResult < ( Option < & ' k str > , Option < & ' k str > ) > {
52
- if let Some ( ( k, v) ) = krate. and_then ( |k| k. split_once ( '@' ) ) {
53
- if version. is_some ( ) {
54
- anyhow:: bail!( "cannot specify both `@{v}` and `--version`" ) ;
55
- }
56
- if k. is_empty ( ) {
57
- // by convention, arguments starting with `@` are response files
58
- anyhow:: bail!( "missing crate name for `@{v}`" ) ;
46
+ krate : Option < & ' k str > ,
47
+ version : Option < & ' k str > ,
48
+ ) -> crate :: CargoResult < ( Option < & ' k str > , & ' k str ) > {
49
+ match krate. and_then ( |k| k. split_once ( '@' ) ) {
50
+ Some ( ( name, embedded_version) ) => {
51
+ if name. is_empty ( ) {
52
+ // by convention, arguments starting with `@` are response files
53
+ anyhow:: bail!( "missing crate name for `@{embedded_version}`" ) ;
54
+ }
55
+
56
+ match version {
57
+ None => Ok ( ( Some ( name) , embedded_version) ) ,
58
+ Some ( _) => {
59
+ anyhow:: bail!( "cannot specify both `@{embedded_version}` and `--version`" ) ;
60
+ }
61
+ }
59
62
}
60
- krate = Some ( k) ;
61
- version = Some ( v) ;
63
+ None => match version {
64
+ Some ( version) => Ok ( ( krate, version) ) ,
65
+ None => {
66
+ anyhow:: bail!( "`--version` is required" ) ;
67
+ }
68
+ } ,
62
69
}
63
- Ok ( ( krate, version) )
64
70
}
0 commit comments