diff --git a/src/bin/cargo/commands/owner.rs b/src/bin/cargo/commands/owner.rs index 45f34bc8e80..dd2ba85dbf2 100644 --- a/src/bin/cargo/commands/owner.rs +++ b/src/bin/cargo/commands/owner.rs @@ -6,14 +6,18 @@ 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) + .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), ) .arg( multi_opt( @@ -21,9 +25,46 @@ pub fn cli() -> Command { "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!( + "cargo owner add <> [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!( + "cargo owner remove <> [CRATE_NAME] [OPTIONS]" + )), + Command::new("list") + .about("List owners of a crate") + .args(add_registry_args()) + .override_usage(color_print::cstr!( + "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::("add") + .map(|xs| xs.cloned().collect::>()), + None, + false, + ), + Some(("remove", subargs)) => ( + None, + subargs + .get_many::("remove") + .map(|xs| xs.cloned().collect()), + false, + ), + Some(("list", _)) => (None, None, true), + _ => ( + args.get_many::("add") + .map(|xs| xs.cloned().collect::>()), + args.get_many::("remove") + .map(|xs| xs.cloned().collect()), + args.flag("list"), + ), + }; + + 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::("crate").cloned(), - token: args.get_one::("token").cloned().map(Secret::from), - reg_or_index: args.registry_or_index(config)?, - to_add: args - .get_many::("add") - .map(|xs| xs.cloned().collect()), - to_remove: args - .get_many::("remove") - .map(|xs| xs.cloned().collect()), - list: args.flag("list"), + krate: common_args.clone().get_one::("crate").cloned(), + token: common_args + .get_one::("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(()) } diff --git a/src/doc/man/cargo-owner.md b/src/doc/man/cargo-owner.md index 32791696887..cc8ad3e1acb 100644 --- a/src/doc/man/cargo-owner.md +++ b/src/doc/man/cargo-owner.md @@ -6,9 +6,9 @@ cargo-owner --- Manage the owners of a crate on the registry ## SYNOPSIS -`cargo owner` [_options_] `--add` _login_ [_crate_]\ -`cargo owner` [_options_] `--remove` _login_ [_crate_]\ -`cargo owner` [_options_] `--list` [_crate_] +`cargo owner` `add` _login_ [_crate_] [_options_]\ +`cargo owner` `remove` _login_ [_crate_] [_options_]\ +`cargo owner` `list` [_crate_] [_options_] ## DESCRIPTION @@ -27,22 +27,28 @@ information about owners and publishing. ## OPTIONS -### Owner Options +### Subcommand {{#options}} -{{#option "`-a`" "`--add` _login_..." }} +{{#option "`add` _login_..." }} Invite the given user or team as an owner. {{/option}} -{{#option "`-r`" "`--remove` _login_..." }} +{{#option "`remove` _login_..." }} Remove the given user or team as an owner. {{/option}} -{{#option "`-l`" "`--list`" }} +{{#option "`list`" }} List owners of a crate. {{/option}} +{{/options}} + +### Owner Options + +{{#options}} + {{> options-token }} {{> options-index }} @@ -67,15 +73,15 @@ List owners of a crate. 1. List owners of a package: - cargo owner --list foo + cargo owner list foo 2. Invite an owner to a package: - cargo owner --add username foo + cargo owner add username foo 3. Remove an owner from a package: - cargo owner --remove username foo + cargo owner remove username foo ## SEE ALSO {{man "cargo" 1}}, {{man "cargo-login" 1}}, {{man "cargo-publish" 1}} diff --git a/src/doc/man/generated_txt/cargo-owner.txt b/src/doc/man/generated_txt/cargo-owner.txt index a77975da008..b9721f1c02a 100644 --- a/src/doc/man/generated_txt/cargo-owner.txt +++ b/src/doc/man/generated_txt/cargo-owner.txt @@ -4,9 +4,9 @@ NAME cargo-owner — Manage the owners of a crate on the registry SYNOPSIS - cargo owner [options] --add login [crate] - cargo owner [options] --remove login [crate] - cargo owner [options] --list [crate] + cargo owner add login [crate] [options] + cargo owner remove login [crate] [options] + cargo owner list [crate] [options] DESCRIPTION This command will modify the owners for a crate on the registry. Owners @@ -24,16 +24,17 @@ DESCRIPTION for more information about owners and publishing. OPTIONS - Owner Options - -a, --add login… + Subcommand + add login… Invite the given user or team as an owner. - -r, --remove login… + remove login… Remove the given user or team as an owner. - -l, --list + list List owners of a crate. + Owner Options --token token API token to use when authenticating. This overrides the token stored in the credentials file (which is created by cargo-login(1)). @@ -131,15 +132,15 @@ EXIT STATUS EXAMPLES 1. List owners of a package: - cargo owner --list foo + cargo owner list foo 2. Invite an owner to a package: - cargo owner --add username foo + cargo owner add username foo 3. Remove an owner from a package: - cargo owner --remove username foo + cargo owner remove username foo SEE ALSO cargo(1), cargo-login(1), cargo-publish(1) diff --git a/src/doc/src/commands/cargo-owner.md b/src/doc/src/commands/cargo-owner.md index 7dba77cd9e0..28085b58403 100644 --- a/src/doc/src/commands/cargo-owner.md +++ b/src/doc/src/commands/cargo-owner.md @@ -6,9 +6,9 @@ cargo-owner --- Manage the owners of a crate on the registry ## SYNOPSIS -`cargo owner` [_options_] `--add` _login_ [_crate_]\ -`cargo owner` [_options_] `--remove` _login_ [_crate_]\ -`cargo owner` [_options_] `--list` [_crate_] +`cargo owner` `add` _login_ [_crate_] [_options_]\ +`cargo owner` `remove` _login_ [_crate_] [_options_]\ +`cargo owner` `list` [_crate_] [_options_] ## DESCRIPTION @@ -27,25 +27,28 @@ information about owners and publishing. ## OPTIONS -### Owner Options +### Subcommand
-
-a
-
--add login
+
add login
Invite the given user or team as an owner.
-
-r
-
--remove login
+
remove login
Remove the given user or team as an owner.
-
-l
-
--list
+
list
List owners of a crate.
+
+ +### Owner Options + +
+
--token token
API token to use when authenticating. This overrides the token stored in the credentials file (which is created by cargo-login(1)).

@@ -155,15 +158,15 @@ details on environment variables that Cargo reads. 1. List owners of a package: - cargo owner --list foo + cargo owner list foo 2. Invite an owner to a package: - cargo owner --add username foo + cargo owner add username foo 3. Remove an owner from a package: - cargo owner --remove username foo + cargo owner remove username foo ## SEE ALSO [cargo(1)](cargo.html), [cargo-login(1)](cargo-login.html), [cargo-publish(1)](cargo-publish.html) diff --git a/src/doc/src/reference/publishing.md b/src/doc/src/reference/publishing.md index 5dcb73d0f3d..7223e31f3ea 100644 --- a/src/doc/src/reference/publishing.md +++ b/src/doc/src/reference/publishing.md @@ -186,22 +186,22 @@ may change over time! The owner of a crate is the only person allowed to publish new versions of the crate, but an owner may designate additional owners. ```console -$ cargo owner --add github-handle -$ cargo owner --remove github-handle -$ cargo owner --add github:rust-lang:owners -$ cargo owner --remove github:rust-lang:owners +$ cargo owner add github-handle +$ cargo owner remove github-handle +$ cargo owner add github:rust-lang:owners +$ cargo owner remove github:rust-lang:owners ``` The owner IDs given to these commands must be GitHub user names or GitHub teams. -If a user name is given to `--add`, that user is invited as a “named” owner, with +If a user name is given to `add`, that user is invited as a “named” owner, with full rights to the crate. In addition to being able to publish or yank versions of the crate, they have the ability to add or remove owners, *including* the owner that made *them* an owner. Needless to say, you shouldn’t make people you don’t fully trust into a named owner. In order to become a named owner, a user must have logged into [crates.io] previously. -If a team name is given to `--add`, that team is invited as a “team” owner, with +If a team name is given to `add`, that team is invited as a “team” owner, with restricted right to the crate. While they have permission to publish or yank versions of the crate, they *do not* have the ability to add or remove owners. In addition to being more convenient for managing groups of owners, teams are diff --git a/src/etc/_cargo b/src/etc/_cargo index 7fb3352523d..8c6264d733a 100644 --- a/src/etc/_cargo +++ b/src/etc/_cargo @@ -153,8 +153,7 @@ _cargo() { '--allow-dirty[fix code even if the working directory is dirty]' \ '--allow-staged[fix code even if the working directory has staged changes]' \ '--ignore-rust-version[Ignore rust-version specification in packages]' - ;; - + ;; generate-lockfile) _arguments -s -S $common $manifest ;; @@ -218,9 +217,11 @@ _cargo() { _arguments -s -S $common $registry \ '(-a --add)'{-a,--add}'[specify name of a user or team to invite as an owner]:name' \ '--index=[specify registry index]:index' \ + '--crate=[Crate name that you want to manage the owner]:crate' \ '(-l --list)'{-l,--list}'[list owners of a crate]' \ '(-r --remove)'{-r,--remove}'[specify name of a user or team to remove as an owner]:name' \ '--token=[specify API token to use when authenticating]:token' \ + '(--add -a --remove -r --list -l 1): :_cargo_owner_subcommand' \ '*: :_guard "^-*" "crate"' ;; @@ -378,6 +379,17 @@ _cargo() { esac } +_cargo_owner_subcommand() { + local -a subcommands + + subcommands=( + 'add:specify name of a user or team to invite as an owner' + 'remove:specify name of a user or team to remove as an owner' + 'list:list owners of a crate' + ) + _describe -t subcommands 'command' subcommands +} + _cargo_unstable_flags() { local flags flags=( help ${${${(M)${(f)"$(_call_program flags cargo -Z help)"}:#*--*}/ #-- #/:}##*-Z } ) diff --git a/src/etc/cargo.bashcomp.sh b/src/etc/cargo.bashcomp.sh old mode 100644 new mode 100755 index c0ba62752c0..0026e929b8e --- a/src/etc/cargo.bashcomp.sh +++ b/src/etc/cargo.bashcomp.sh @@ -69,7 +69,10 @@ _cargo() local opt__login="$opt_common $opt_lock --registry" local opt__metadata="$opt_common $opt_feat $opt_mani $opt_lock --format-version=1 --no-deps --filter-platform" local opt__new="$opt_common $opt_lock --vcs --bin --lib --name --edition --registry" - local opt__owner="$opt_common $opt_lock -a --add -r --remove -l --list --index --token --registry" + local opt__owner="$opt_common $opt_lock add remove list -a --add -r --remove -l --list --index --token --registry" + local opt__owner_add="$opt_common $opt_lock --crate --index --token --registry" + local opt__owner_remove="$opt_common $opt_lock --crate --index --token --registry" + local opt__owner_list="$opt_common $opt_lock --crate --index --token --registry" local opt__package="$opt_common $opt_mani $opt_feat $opt_lock $opt_parallel --allow-dirty -l --list --no-verify --no-metadata --target --target-dir" local opt__pkgid="$opt_common $opt_mani $opt_lock $opt_pkg" local opt__publish="$opt_common $opt_mani $opt_feat $opt_lock $opt_parallel --allow-dirty --dry-run --token --no-verify --index --registry --target --target-dir" diff --git a/src/etc/man/cargo-owner.1 b/src/etc/man/cargo-owner.1 index 82cac16aae3..a97896f05f8 100644 --- a/src/etc/man/cargo-owner.1 +++ b/src/etc/man/cargo-owner.1 @@ -6,11 +6,11 @@ .SH "NAME" cargo\-owner \[em] Manage the owners of a crate on the registry .SH "SYNOPSIS" -\fBcargo owner\fR [\fIoptions\fR] \fB\-\-add\fR \fIlogin\fR [\fIcrate\fR] +\fBcargo owner\fR \fBadd\fR \fIlogin\fR [\fIcrate\fR] [\fIoptions\fR] .br -\fBcargo owner\fR [\fIoptions\fR] \fB\-\-remove\fR \fIlogin\fR [\fIcrate\fR] +\fBcargo owner\fR \fBremove\fR \fIlogin\fR [\fIcrate\fR] [\fIoptions\fR] .br -\fBcargo owner\fR [\fIoptions\fR] \fB\-\-list\fR [\fIcrate\fR] +\fBcargo owner\fR \fBlist\fR [\fIcrate\fR] [\fIoptions\fR] .SH "DESCRIPTION" This command will modify the owners for a crate on the registry. Owners of a crate can upload new versions and yank old versions. Non\-team owners can also @@ -25,25 +25,23 @@ current directory. See \fIthe reference\fR for more information about owners and publishing. .SH "OPTIONS" -.SS "Owner Options" +.SS "Subcommand" .sp -\fB\-a\fR, -\fB\-\-add\fR \fIlogin\fR\[u2026] +\fBadd\fR \fIlogin\fR\[u2026] .RS 4 Invite the given user or team as an owner. .RE .sp -\fB\-r\fR, -\fB\-\-remove\fR \fIlogin\fR\[u2026] +\fBremove\fR \fIlogin\fR\[u2026] .RS 4 Remove the given user or team as an owner. .RE .sp -\fB\-l\fR, -\fB\-\-list\fR +\fBlist\fR .RS 4 List owners of a crate. .RE +.SS "Owner Options" .sp \fB\-\-token\fR \fItoken\fR .RS 4 @@ -169,7 +167,7 @@ details on environment variables that Cargo reads. .sp .RS 4 .nf -cargo owner \-\-list foo +cargo owner list foo .fi .RE .RE @@ -179,7 +177,7 @@ cargo owner \-\-list foo .sp .RS 4 .nf -cargo owner \-\-add username foo +cargo owner add username foo .fi .RE .RE @@ -189,7 +187,7 @@ cargo owner \-\-add username foo .sp .RS 4 .nf -cargo owner \-\-remove username foo +cargo owner remove username foo .fi .RE .RE diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index e347af1c708..06f891c3284 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -730,7 +730,7 @@ Caused by: "init", "install foo", "login", - "owner", + "owner list", "publish", "search", "yank --version 0.0.1", @@ -797,7 +797,7 @@ fn no_api() { .with_stderr_contains(&err) .run(); - p.cargo("owner --registry alternative --list") + p.cargo("owner list --registry alternative") .with_status(101) .with_stderr_contains(&err) .run(); @@ -1409,7 +1409,7 @@ fn both_index_and_default() { let p = project().file("src/lib.rs", "").build(); for cmd in &[ "publish", - "owner", + "owner list", "search", "yank --version 1.0.0", "install foo", diff --git a/tests/testsuite/cargo_owner/add_help/mod.rs b/tests/testsuite/cargo_owner/add_help/mod.rs new file mode 100644 index 00000000000..7262c3de268 --- /dev/null +++ b/tests/testsuite/cargo_owner/add_help/mod.rs @@ -0,0 +1,14 @@ +use cargo_test_support::curr_dir; +use cargo_test_support::prelude::*; + +#[cargo_test] +fn add_case() { + snapbox::cmd::Command::cargo_ui() + .arg("owner") + .arg("add") + .arg("--help") + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); +} diff --git a/tests/testsuite/cargo_owner/add_help/stderr.log b/tests/testsuite/cargo_owner/add_help/stderr.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_owner/add_help/stdout.log b/tests/testsuite/cargo_owner/add_help/stdout.log new file mode 100644 index 00000000000..5d3bfe0901e --- /dev/null +++ b/tests/testsuite/cargo_owner/add_help/stdout.log @@ -0,0 +1,20 @@ +Name of a user or team to invite as an owner + +Usage: cargo owner add [CRATE_NAME] [OPTIONS] + +Options: + --crate Crate name that you want to manage the owner + --index Registry index URL to modify owners for + --registry Registry to modify owners for + --token API token to use when authenticating + -v, --verbose... Use verbose output (-vv very verbose/build.rs output) + -q, --quiet Do not print cargo log messages + --color Coloring: auto, always, never + --config Override a configuration value + -Z Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details + -h, --help Print help + +Manifest Options: + --frozen Require Cargo.lock and cache are up to date + --locked Require Cargo.lock is up to date + --offline Run without accessing the network diff --git a/tests/testsuite/cargo_owner/help/stdout.log b/tests/testsuite/cargo_owner/help/stdout.log index b6f436d047b..a0a865cebaa 100644 --- a/tests/testsuite/cargo_owner/help/stdout.log +++ b/tests/testsuite/cargo_owner/help/stdout.log @@ -1,14 +1,11 @@ Manage the owners of a crate on the registry -Usage: cargo[EXE] owner [OPTIONS] [CRATE] - -Arguments: - [CRATE] +Usage: cargo[EXE] owner [OPTIONS] + cargo owner add [CRATE_NAME] [OPTIONS] + cargo owner remove [CRATE_NAME] [OPTIONS] + cargo owner list [CRATE_NAME] [OPTIONS] Options: - -a, --add Name of a user or team to invite as an owner - -r, --remove Name of a user or team to remove as an owner - -l, --list List owners of a crate --index Registry index URL to modify owners for --registry Registry to modify owners for --token API token to use when authenticating @@ -24,4 +21,28 @@ Manifest Options: --locked Require Cargo.lock is up to date --offline Run without accessing the network +cargo[EXE] owner add: +Name of a user or team to invite as an owner + --crate Crate name that you want to manage the owner + --index Registry index URL to modify owners for + --registry Registry to modify owners for + --token API token to use when authenticating + -h, --help Print help + +cargo[EXE] owner remove: +Name of a user or team to remove as an owner + --crate Crate name that you want to manage the owner + --index Registry index URL to modify owners for + --registry Registry to modify owners for + --token API token to use when authenticating + -h, --help Print help + +cargo[EXE] owner list: +List owners of a crate + --crate Crate name that you want to manage the owner + --index Registry index URL to modify owners for + --registry Registry to modify owners for + --token API token to use when authenticating + -h, --help Print help + Run `cargo help owner` for more detailed information. diff --git a/tests/testsuite/cargo_owner/list_help/mod.rs b/tests/testsuite/cargo_owner/list_help/mod.rs new file mode 100644 index 00000000000..a5d3543d4de --- /dev/null +++ b/tests/testsuite/cargo_owner/list_help/mod.rs @@ -0,0 +1,14 @@ +use cargo_test_support::curr_dir; +use cargo_test_support::prelude::*; + +#[cargo_test] +fn list_case() { + snapbox::cmd::Command::cargo_ui() + .arg("owner") + .arg("list") + .arg("--help") + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); +} diff --git a/tests/testsuite/cargo_owner/list_help/stderr.log b/tests/testsuite/cargo_owner/list_help/stderr.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_owner/list_help/stdout.log b/tests/testsuite/cargo_owner/list_help/stdout.log new file mode 100644 index 00000000000..0c563de0ec9 --- /dev/null +++ b/tests/testsuite/cargo_owner/list_help/stdout.log @@ -0,0 +1,20 @@ +List owners of a crate + +Usage: cargo owner list [CRATE_NAME] [OPTIONS] + +Options: + --crate Crate name that you want to manage the owner + --index Registry index URL to modify owners for + --registry Registry to modify owners for + --token API token to use when authenticating + -v, --verbose... Use verbose output (-vv very verbose/build.rs output) + -q, --quiet Do not print cargo log messages + --color Coloring: auto, always, never + --config Override a configuration value + -Z Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details + -h, --help Print help + +Manifest Options: + --frozen Require Cargo.lock and cache are up to date + --locked Require Cargo.lock is up to date + --offline Run without accessing the network diff --git a/tests/testsuite/cargo_owner/mod.rs b/tests/testsuite/cargo_owner/mod.rs index c0ce1118071..bea7a05a2ca 100644 --- a/tests/testsuite/cargo_owner/mod.rs +++ b/tests/testsuite/cargo_owner/mod.rs @@ -1 +1,4 @@ +mod add_help; mod help; +mod list_help; +mod remove_help; diff --git a/tests/testsuite/cargo_owner/remove_help/mod.rs b/tests/testsuite/cargo_owner/remove_help/mod.rs new file mode 100644 index 00000000000..2800a9634a2 --- /dev/null +++ b/tests/testsuite/cargo_owner/remove_help/mod.rs @@ -0,0 +1,14 @@ +use cargo_test_support::curr_dir; +use cargo_test_support::prelude::*; + +#[cargo_test] +fn remove_case() { + snapbox::cmd::Command::cargo_ui() + .arg("owner") + .arg("remove") + .arg("--help") + .assert() + .success() + .stdout_matches_path(curr_dir!().join("stdout.log")) + .stderr_matches_path(curr_dir!().join("stderr.log")); +} diff --git a/tests/testsuite/cargo_owner/remove_help/stderr.log b/tests/testsuite/cargo_owner/remove_help/stderr.log new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_owner/remove_help/stdout.log b/tests/testsuite/cargo_owner/remove_help/stdout.log new file mode 100644 index 00000000000..bc4872cb8a8 --- /dev/null +++ b/tests/testsuite/cargo_owner/remove_help/stdout.log @@ -0,0 +1,20 @@ +Name of a user or team to remove as an owner + +Usage: cargo owner remove [CRATE_NAME] [OPTIONS] + +Options: + --crate Crate name that you want to manage the owner + --index Registry index URL to modify owners for + --registry Registry to modify owners for + --token API token to use when authenticating + -v, --verbose... Use verbose output (-vv very verbose/build.rs output) + -q, --quiet Do not print cargo log messages + --color Coloring: auto, always, never + --config Override a configuration value + -Z Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details + -h, --help Print help + +Manifest Options: + --frozen Require Cargo.lock and cache are up to date + --locked Require Cargo.lock is up to date + --offline Run without accessing the network diff --git a/tests/testsuite/owner.rs b/tests/testsuite/owner.rs index fc0e0b5c4e2..710ded10b96 100644 --- a/tests/testsuite/owner.rs +++ b/tests/testsuite/owner.rs @@ -47,15 +47,18 @@ fn simple_list() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("owner -l") - .replace_crates_io(registry.index_url()) - .with_stdout( - "\ + let commands = ["-l", "--list", "list"]; + for command in commands.iter() { + p.cargo(&format!("owner {}", command)) + .replace_crates_io(registry.index_url()) + .with_stdout( + "\ github:rust-lang:core (Core) octocat ", - ) - .run(); + ) + .run(); + } } #[cargo_test] @@ -78,7 +81,7 @@ fn simple_add() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("owner -a username") + p.cargo("owner add username") .replace_crates_io(registry.index_url()) .with_status(101) .with_stderr( @@ -91,6 +94,40 @@ Caused by: .run(); } +#[cargo_test] +fn simple_remove() { + let registry = registry::init(); + setup("foo", None); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + license = "MIT" + description = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("owner remove username") + .replace_crates_io(registry.index_url()) + .with_status(101) + .with_stderr( + " Updating crates.io index + Owner removing [\"username\"] from crate foo +error: failed to remove owners from crate `foo` on registry at file://[..] + +Caused by: + EOF while parsing a value at line 1 column 0", + ) + .run(); +} + #[cargo_test] fn simple_add_with_asymmetric() { let registry = registry::RegistryBuilder::new() @@ -125,15 +162,18 @@ fn simple_add_with_asymmetric() { } #[cargo_test] -fn simple_remove() { - let registry = registry::init(); +fn simple_subcommand_add_with_asymmetric() { + let registry = registry::RegistryBuilder::new() + .http_api() + .token(cargo_test_support::registry::Token::rfc_key()) + .build(); setup("foo", None); let p = project() .file( "Cargo.toml", r#" - [package] + [project] name = "foo" version = "0.0.1" authors = [] @@ -144,17 +184,13 @@ fn simple_remove() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("owner -r username") + // The http_api server will check that the authorization is correct. + // If the authorization was not sent then we would get an unauthorized error. + p.cargo("owner add username") + .arg("-Zasymmetric-token") + .masquerade_as_nightly_cargo(&["asymmetric-token"]) .replace_crates_io(registry.index_url()) - .with_status(101) - .with_stderr( - " Updating crates.io index - Owner removing [\"username\"] from crate foo -error: failed to remove owners from crate `foo` on registry at file://[..] - -Caused by: - EOF while parsing a value at line 1 column 0", - ) + .with_status(0) .run(); } @@ -190,3 +226,36 @@ fn simple_remove_with_asymmetric() { .with_status(0) .run(); } + +#[cargo_test] +fn simple_subcommand_remove_with_asymmetric() { + let registry = registry::RegistryBuilder::new() + .http_api() + .token(cargo_test_support::registry::Token::rfc_key()) + .build(); + setup("foo", None); + + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + license = "MIT" + description = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + // The http_api server will check that the authorization is correct. + // If the authorization was not sent then we would get an unauthorized error. + p.cargo("owner remove username") + .arg("-Zasymmetric-token") + .replace_crates_io(registry.index_url()) + .masquerade_as_nightly_cargo(&["asymmetric-token"]) + .with_status(0) + .run(); +}