-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Support cargo owner add
#11879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support cargo owner add
#11879
Changes from all commits
786e0b6
9bef78d
5862698
8914b1a
6573a9e
baf3020
0ae910a
efaf17b
6037751
3a99929
1423140
a2a59ea
08be20f
e038e62
21afbcf
1ef930f
a8b46be
33ca2b8
daaa8c1
fc7987e
5a988dd
3fc6b53
1dc82ae
415bbf6
60ebb2a
3fa434d
3678dff
7acc02f
bd2f6ef
13fccb2
bf304aa
97d2596
0987b72
05c1653
1bc57c7
b722762
01701f7
9f7e9bd
b01c084
3e1914e
6d2b554
48b5429
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,24 +6,65 @@ use cargo_credential::Secret; | |
pub fn cli() -> Command { | ||
subcommand("owner") | ||
.about("Manage the owners of a crate on the registry") | ||
.arg(Arg::new("crate").value_name("CRATE").action(ArgAction::Set)) | ||
.arg_required_else_help(true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm mixed about whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think any results should be shown without explicit user action. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lot of CLIs default a command to list. However, since this is a network operation, I can see foregoing that. As this is an error, we can change it in the future. |
||
.args_conflicts_with_subcommands(true) | ||
.flatten_help(true) | ||
.arg(Arg::new("crate").hide(true)) | ||
.arg( | ||
multi_opt( | ||
"add", | ||
"LOGIN", | ||
"Name of a user or team to invite as an owner", | ||
) | ||
.short('a'), | ||
.short('a') | ||
.hide(true), | ||
) | ||
epage marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.arg( | ||
multi_opt( | ||
"remove", | ||
"LOGIN", | ||
"Name of a user or team to remove as an owner", | ||
) | ||
.short('r'), | ||
.short('r') | ||
.hide(true), | ||
) | ||
.arg(flag("list", "List owners of a crate").short('l')) | ||
.arg(flag("list", "List owners of a crate").short('l').hide(true)) | ||
.subcommands([ | ||
Command::new("add") | ||
.about("Name of a user or team to invite as an owner") | ||
.arg( | ||
Arg::new("add") | ||
.required(true) | ||
.value_delimiter(',') | ||
.value_name("OWNER_NAME") | ||
.hide(true) | ||
.help("Name of the owner you want to invite"), | ||
) | ||
.args(add_registry_args()) | ||
.override_usage(color_print::cstr!( | ||
"<cyan,bold>cargo owner add <<OWNER_NAME>> [CRATE_NAME] [OPTIONS]</>" | ||
)), | ||
Command::new("remove") | ||
.about("Name of a user or team to remove as an owner") | ||
.arg( | ||
Arg::new("remove") | ||
.required(true) | ||
.value_delimiter(',') | ||
.value_name("OWNER_NAME") | ||
.hide(true) | ||
.help("Name of the owner you want to remove"), | ||
) | ||
.args(add_registry_args()) | ||
.override_usage(color_print::cstr!( | ||
"<cyan,bold>cargo owner remove <<OWNER_NAME>> [CRATE_NAME] [OPTIONS]</>" | ||
)), | ||
Command::new("list") | ||
.about("List owners of a crate") | ||
.args(add_registry_args()) | ||
.override_usage(color_print::cstr!( | ||
"<cyan,bold>cargo owner list [CRATE_NAME] [OPTIONS]</>" | ||
)), | ||
]) | ||
.arg_index("Registry index URL to modify owners for") | ||
.arg_registry("Registry to modify owners for") | ||
.arg(opt("token", "API token to use when authenticating").value_name("TOKEN")) | ||
|
@@ -33,19 +74,71 @@ pub fn cli() -> Command { | |
)) | ||
} | ||
|
||
fn add_registry_args() -> [Arg; 4] { | ||
[ | ||
opt("crate", "Crate name that you want to manage the owner").value_name("CRATE_NAME"), | ||
opt("index", "Registry index URL to modify owners for") | ||
.value_name("INDEX") | ||
.conflicts_with("registry"), | ||
opt("registry", "Registry to modify owners for").value_name("REGISTRY"), | ||
opt("token", "API token to use when authenticating").value_name("TOKEN"), | ||
] | ||
} | ||
|
||
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { | ||
let (to_add, to_remove, list) = match args.subcommand() { | ||
Some(("add", subargs)) => ( | ||
subargs | ||
.get_many::<String>("add") | ||
.map(|xs| xs.cloned().collect::<Vec<String>>()), | ||
None, | ||
false, | ||
), | ||
Some(("remove", subargs)) => ( | ||
None, | ||
subargs | ||
.get_many::<String>("remove") | ||
.map(|xs| xs.cloned().collect()), | ||
false, | ||
), | ||
Some(("list", _)) => (None, None, true), | ||
_ => ( | ||
args.get_many::<String>("add") | ||
.map(|xs| xs.cloned().collect::<Vec<String>>()), | ||
args.get_many::<String>("remove") | ||
.map(|xs| xs.cloned().collect()), | ||
args.flag("list"), | ||
), | ||
Comment on lines
+105
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is meant to operate for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there are no subcommands or any parameters(like: |
||
}; | ||
|
||
if (to_add.clone(), to_remove.clone(), list) == (None, None, false) { | ||
return Err(CliError::new( | ||
anyhow::format_err!( | ||
" please enter correct subcommand or parameter.\n | ||
enter `cargo owner --help` for help." | ||
), | ||
101, | ||
)); | ||
} | ||
|
||
let common_args = args.subcommand().map(|(_, args)| args).unwrap_or(args); | ||
|
||
let opts = OwnersOptions { | ||
krate: args.get_one::<String>("crate").cloned(), | ||
token: args.get_one::<String>("token").cloned().map(Secret::from), | ||
reg_or_index: args.registry_or_index(config)?, | ||
to_add: args | ||
.get_many::<String>("add") | ||
.map(|xs| xs.cloned().collect()), | ||
to_remove: args | ||
.get_many::<String>("remove") | ||
.map(|xs| xs.cloned().collect()), | ||
list: args.flag("list"), | ||
krate: common_args.clone().get_one::<String>("crate").cloned(), | ||
token: common_args | ||
.get_one::<String>("token") | ||
.cloned() | ||
.map(Secret::from), | ||
reg_or_index: args | ||
.subcommand() | ||
.map_or(args.registry_or_index(config), |v| { | ||
v.1.registry_or_index(config) | ||
})?, | ||
to_add, | ||
to_remove, | ||
list, | ||
}; | ||
|
||
ops::modify_owners(config, &opts)?; | ||
Ok(()) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.