-
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 30 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,24 +6,73 @@ 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(Arg::new("crate").hide(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. Something we've not talked about is the stabilization plan. Options
Another benefit to stabilizing later is we can re-evaluate this command to see if there are any "breaking" changes we want to make. For example, would we want 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 am learning the operating rules of the community and I can cooperate with your decisions. |
||
.arg_required_else_help(true) | ||
epage marked this conversation as resolved.
Show resolved
Hide resolved
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) | ||
.override_usage( | ||
"\ | ||
cargo[EXE] owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS] | ||
cargo[EXE] owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS] | ||
cargo[EXE] owner list [CRATE_NAME] [OPTIONS]", | ||
) | ||
.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") | ||
.args([ | ||
Arg::new("add") | ||
.required(true) | ||
.value_delimiter(',') | ||
.value_name("OWNER_NAME") | ||
.help("Name of the owner you want to invite"), | ||
Arg::new("crate") | ||
.value_name("CRATE_NAME") | ||
.help("Crate name that you want to manage the owner"), | ||
]) | ||
.args(&add_registry_args()) | ||
heisen-li marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.override_usage("cargo owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS]"), | ||
Command::new("remove") | ||
.about("Name of a user or team to remove as an owner") | ||
.args([ | ||
Arg::new("remove") | ||
.required(true) | ||
.value_delimiter(',') | ||
.value_name("OWNER_NAME") | ||
.help("Name of the owner you want to remove"), | ||
Arg::new("crate") | ||
.value_name("CRATE_NAME") | ||
.help("Crate name that you want to manage the owner"), | ||
]) | ||
.args(&add_registry_args()) | ||
.override_usage("cargo owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]"), | ||
Command::new("list") | ||
.about("List owners of a crate") | ||
.arg( | ||
Arg::new("crate") | ||
.value_name("CRATE_NAME") | ||
.help("Crate name which you want to list all owner names"), | ||
) | ||
.args(&add_registry_args()) | ||
.override_usage("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 +82,70 @@ pub fn cli() -> Command { | |
)) | ||
} | ||
|
||
fn add_registry_args() -> [Arg; 3] { | ||
[ | ||
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: |
||
}; | ||
|
||
let common_args = args.subcommand().map(|(_, args)| args).unwrap_or(args); | ||
|
||
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 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(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,9 +217,12 @@ _cargo() { | |
owner) | ||
_arguments -s -S $common $registry \ | ||
'(-a --add)'{-a,--add}'[specify name of a user or team to invite as an owner]:name' \ | ||
'(add)'{add}'[specify name of a user or team to invite as an owner]:name' \ | ||
'--index=[specify registry index]:index' \ | ||
'(-l --list)'{-l,--list}'[list owners of a crate]' \ | ||
'(list)'{list}'[list owners of a crate]' \ | ||
'(-r --remove)'{-r,--remove}'[specify name of a user or team to remove as an owner]:name' \ | ||
'(remove)'{remove}'[specify name of a user or team to remove as an owner]:name' \ | ||
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 suspect these will let us complete the subcommand names but not the arguments underneath? Or if they do, it'll report all the arguments underneath? Unfortunately, it looks like zsh completions are missing 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. Command completion for zsh is a bit difficult for me and I'm learning how to accomplish this. 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've tried to finish. In addition, whether |
||
'--token=[specify API token to use when authenticating]:token' \ | ||
'*: :_guard "^-*" "crate"' | ||
;; | ||
|
Uh oh!
There was an error while loading. Please reload this page.