@@ -35,44 +35,43 @@ pub fn cli() -> Command {
35
35
)
36
36
. arg ( flag ( "list" , "List owners of a crate" ) . short ( 'l' ) . hide ( true ) )
37
37
. subcommands ( [
38
- add_registry_args (
39
- Command :: new ( "add" )
40
- . about ( "Name of a user or team to invite as an owner" )
41
- . args ( [
42
- Arg :: new ( "add" )
43
- . required ( true )
44
- . value_delimiter ( ',' )
45
- . value_name ( "OWNER_NAME" )
46
- . help ( "Name of the owner you want to invite" ) ,
47
- Arg :: new ( "crate" )
48
- . value_name ( "CRATE_NAME" )
49
- . help ( "Crate name that you want to manage the owner" ) ,
50
- ] ) ,
51
- )
52
- . override_usage ( "cargo owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS]" ) ,
53
- add_registry_args (
54
- Command :: new ( "remove" )
55
- . about ( "Name of a user or team to remove as an owner" )
56
- . args ( [
57
- Arg :: new ( "remove" )
58
- . required ( true )
59
- . value_delimiter ( ',' )
60
- . value_name ( "OWNER_NAME" )
61
- . help ( "Name of the owner you want to remove" ) ,
62
- Arg :: new ( "crate" )
63
- . value_name ( "CRATE_NAME" )
64
- . help ( "Crate name that you want to manage the owner" ) ,
65
- ] ) ,
66
- )
67
- . override_usage ( "cargo owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]" ) ,
68
- add_registry_args (
69
- Command :: new ( "list" ) . about ( "List owners of a crate" ) . arg (
38
+ Command :: new ( "add" )
39
+ . about ( "Name of a user or team to invite as an owner" )
40
+ . args ( [
41
+ Arg :: new ( "add" )
42
+ . required ( true )
43
+ . value_delimiter ( ',' )
44
+ . value_name ( "OWNER_NAME" )
45
+ . help ( "Name of the owner you want to invite" ) ,
46
+ Arg :: new ( "crate" )
47
+ . value_name ( "CRATE_NAME" )
48
+ . help ( "Crate name that you want to manage the owner" ) ,
49
+ ] )
50
+ . args ( & add_registry_args ( ) )
51
+ . override_usage ( "cargo owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS]" ) ,
52
+ Command :: new ( "remove" )
53
+ . about ( "Name of a user or team to remove as an owner" )
54
+ . args ( [
55
+ Arg :: new ( "remove" )
56
+ . required ( true )
57
+ . value_delimiter ( ',' )
58
+ . value_name ( "OWNER_NAME" )
59
+ . help ( "Name of the owner you want to remove" ) ,
60
+ Arg :: new ( "crate" )
61
+ . value_name ( "CRATE_NAME" )
62
+ . help ( "Crate name that you want to manage the owner" ) ,
63
+ ] )
64
+ . args ( & add_registry_args ( ) )
65
+ . override_usage ( "cargo owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]" ) ,
66
+ Command :: new ( "list" )
67
+ . about ( "List owners of a crate" )
68
+ . arg (
70
69
Arg :: new ( "crate" )
71
70
. value_name ( "CRATE_NAME" )
72
71
. help ( "Crate name which you want to list all owner names" ) ,
73
- ) ,
74
- )
75
- . override_usage ( "cargo owner list [CRATE_NAME] [OPTIONS]" ) ,
72
+ )
73
+ . args ( & add_registry_args ( ) )
74
+ . override_usage ( "cargo owner list [CRATE_NAME] [OPTIONS]" ) ,
76
75
] )
77
76
. arg_index ( "Registry index URL to modify owners for" )
78
77
. arg_registry ( "Registry to modify owners for" )
@@ -83,11 +82,14 @@ pub fn cli() -> Command {
83
82
) )
84
83
}
85
84
86
- fn add_registry_args ( command : Command ) -> Command {
87
- command
88
- . arg_index ( "Registry index URL to modify owners for" )
89
- . arg_registry ( "Registry to modify owners for" )
90
- . arg ( opt ( "token" , "API token to use when authenticating" ) . value_name ( "TOKEN" ) )
85
+ fn add_registry_args ( ) -> [ Arg ; 3 ] {
86
+ [
87
+ opt ( "index" , "Registry index URL to modify owners for" )
88
+ . value_name ( "INDEX" )
89
+ . conflicts_with ( "registry" ) ,
90
+ opt ( "registry" , "Registry to modify owners for" ) . value_name ( "REGISTRY" ) ,
91
+ opt ( "token" , "API token to use when authenticating" ) . value_name ( "TOKEN" ) ,
92
+ ]
91
93
}
92
94
93
95
pub fn exec ( config : & mut Config , args : & ArgMatches ) -> CliResult {
@@ -107,10 +109,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
107
109
false ,
108
110
) ,
109
111
Some ( ( "list" , _) ) => ( None , None , true ) ,
110
- Some ( ( name, _) ) => {
111
- unreachable ! ( "{name} is not a subcommand of cargo owner, please enter `cargo owner --help` for help." )
112
- }
113
- None => (
112
+ _ => (
114
113
args. get_many :: < String > ( "add" )
115
114
. map ( |xs| xs. cloned ( ) . collect :: < Vec < String > > ( ) ) ,
116
115
args. get_many :: < String > ( "remove" )
@@ -121,16 +120,30 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
121
120
122
121
let common_args = args. subcommand ( ) . map ( |( _, args) | args) . unwrap_or ( args) ;
123
122
123
+ if ( to_add. clone ( ) , to_remove. clone ( ) , list) == ( None , None , false ) {
124
+ return Err ( CliError :: new (
125
+ anyhow:: format_err!(
126
+ " please enter correct subcommand or parameter.\n
127
+ enter `cargo owner --help` for help."
128
+ ) ,
129
+ 101 ,
130
+ ) ) ;
131
+ }
132
+
124
133
let opts = OwnersOptions {
125
134
krate : common_args. clone ( ) . get_one :: < String > ( "crate" ) . cloned ( ) ,
126
135
token : common_args
127
136
. get_one :: < String > ( "token" )
128
137
. cloned ( )
129
138
. map ( Secret :: from) ,
130
- reg_or_index : args. registry_or_index ( config) ?,
131
- to_add : to_add,
132
- to_remove : to_remove,
133
- list : list,
139
+ reg_or_index : args
140
+ . subcommand ( )
141
+ . map_or ( args. registry_or_index ( config) , |v| {
142
+ v. 1 . registry_or_index ( config)
143
+ } ) ?,
144
+ to_add,
145
+ to_remove,
146
+ list,
134
147
} ;
135
148
136
149
ops:: modify_owners ( config, & opts) ?;
0 commit comments