Skip to content

Commit 7acc02f

Browse files
committed
fix test and some
1 parent 3fa434d commit 7acc02f

File tree

8 files changed

+70
-52
lines changed

8 files changed

+70
-52
lines changed

src/bin/cargo/commands/owner.rs

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,43 @@ pub fn cli() -> Command {
3535
)
3636
.arg(flag("list", "List owners of a crate").short('l').hide(true))
3737
.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(
7069
Arg::new("crate")
7170
.value_name("CRATE_NAME")
7271
.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]"),
7675
])
7776
.arg_index("Registry index URL to modify owners for")
7877
.arg_registry("Registry to modify owners for")
@@ -83,11 +82,14 @@ pub fn cli() -> Command {
8382
))
8483
}
8584

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+
]
9193
}
9294

9395
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
@@ -107,10 +109,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
107109
false,
108110
),
109111
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+
_ => (
114113
args.get_many::<String>("add")
115114
.map(|xs| xs.cloned().collect::<Vec<String>>()),
116115
args.get_many::<String>("remove")
@@ -121,16 +120,30 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
121120

122121
let common_args = args.subcommand().map(|(_, args)| args).unwrap_or(args);
123122

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+
124133
let opts = OwnersOptions {
125134
krate: common_args.clone().get_one::<String>("crate").cloned(),
126135
token: common_args
127136
.get_one::<String>("token")
128137
.cloned()
129138
.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,
134147
};
135148

136149
ops::modify_owners(config, &opts)?;

src/etc/_cargo

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,12 @@ _cargo() {
217217
owner)
218218
_arguments -s -S $common $registry \
219219
'(-a --add)'{-a,--add}'[specify name of a user or team to invite as an owner]:name' \
220+
'(add)'{add}'[specify name of a user or team to invite as an owner]:name' \
220221
'--index=[specify registry index]:index' \
221222
'(-l --list)'{-l,--list}'[list owners of a crate]' \
223+
'(list)'{list}'[list owners of a crate]' \
222224
'(-r --remove)'{-r,--remove}'[specify name of a user or team to remove as an owner]:name' \
225+
'(remove)'{remove}'[specify name of a user or team to remove as an owner]:name' \
223226
'--token=[specify API token to use when authenticating]:token' \
224227
'*: :_guard "^-*" "crate"'
225228
;;

src/etc/cargo.bashcomp.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ _cargo()
6969
local opt__login="$opt_common $opt_lock --registry"
7070
local opt__metadata="$opt_common $opt_feat $opt_mani $opt_lock --format-version=1 --no-deps --filter-platform"
7171
local opt__new="$opt_common $opt_lock --vcs --bin --lib --name --edition --registry"
72-
local opt__owner="$opt_common $opt_lock -a --add -r --remove -l --list --index --token --registry"
72+
local opt__owner="$opt_common $opt_lock -a --add add -r --remove remove -l --list list --index --token --registry"
7373
local opt__package="$opt_common $opt_mani $opt_feat $opt_lock $opt_parallel --allow-dirty -l --list --no-verify --no-metadata --target --target-dir"
7474
local opt__pkgid="$opt_common $opt_mani $opt_lock $opt_pkg"
7575
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"

tests/testsuite/alt_registry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ Caused by:
723723
"init",
724724
"install foo",
725725
"login",
726-
"owner",
726+
"owner list",
727727
"publish",
728728
"search",
729729
"yank --version 0.0.1",
@@ -1402,7 +1402,7 @@ fn both_index_and_default() {
14021402
let p = project().file("src/lib.rs", "").build();
14031403
for cmd in &[
14041404
"publish",
1405-
"owner",
1405+
"owner list",
14061406
"search",
14071407
"yank --version 1.0.0",
14081408
"install foo",

tests/testsuite/cargo_owner/add_help/stdout.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Options:
1111
--registry <REGISTRY> Registry to modify owners for
1212
--token <TOKEN> API token to use when authenticating
1313
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
14+
-q, --quiet Do not print cargo log messages
1415
--color <WHEN> Coloring: auto, always, never
1516
--config <KEY=VALUE> Override a configuration value
1617
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details

tests/testsuite/cargo_owner/help/stdout.log

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Commands:
1010
list List owners of a crate
1111

1212
Options:
13-
-q, --quiet Do not print cargo log messages
1413
--index <INDEX> Registry index URL to modify owners for
1514
--registry <REGISTRY> Registry to modify owners for
1615
--token <TOKEN> API token to use when authenticating

tests/testsuite/cargo_owner/list_help/stdout.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Options:
1010
--registry <REGISTRY> Registry to modify owners for
1111
--token <TOKEN> API token to use when authenticating
1212
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
13+
-q, --quiet Do not print cargo log messages
1314
--color <WHEN> Coloring: auto, always, never
1415
--config <KEY=VALUE> Override a configuration value
1516
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details

tests/testsuite/cargo_owner/remove_help/stdout.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Options:
1111
--registry <REGISTRY> Registry to modify owners for
1212
--token <TOKEN> API token to use when authenticating
1313
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
14+
-q, --quiet Do not print cargo log messages
1415
--color <WHEN> Coloring: auto, always, never
1516
--config <KEY=VALUE> Override a configuration value
1617
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details

0 commit comments

Comments
 (0)