Skip to content

Commit 1dc82ae

Browse files
committed
add some test & fix some error
1 parent 3fc6b53 commit 1dc82ae

File tree

12 files changed

+128
-22
lines changed

12 files changed

+128
-22
lines changed

src/bin/cargo/commands/owner.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ pub fn cli() -> Command {
1616
cargo owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]
1717
cargo owner list [CRATE_NAME] [OPTIONS]",
1818
)
19-
// The following three parameters are planned to be replaced in the form of subcommands.
20-
// refer to issue: https://github.com/rust-lang/cargo/issues/4352
2119
.arg(
2220
multi_opt(
2321
"add",
@@ -38,10 +36,9 @@ pub fn cli() -> Command {
3836
)
3937
.arg(flag("list", "List owners of a crate").short('l').hide(true))
4038
.subcommands([
41-
for_subcommand_add_arg(
39+
add_registry_args(
4240
Command::new("add")
4341
.about("Name of a user or team to invite as an owner")
44-
.arg_quiet()
4542
.args([
4643
Arg::new("add")
4744
.required(true)
@@ -52,11 +49,11 @@ pub fn cli() -> Command {
5249
.value_name("CRATE_NAME")
5350
.help("Crate name that you want to manage the owner"),
5451
]),
55-
),
56-
for_subcommand_add_arg(
52+
)
53+
.override_usage("cargo owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS]"),
54+
add_registry_args(
5755
Command::new("remove")
5856
.about("Name of a user or team to remove as an owner")
59-
.arg_quiet()
6057
.args([
6158
Arg::new("remove")
6259
.required(true)
@@ -67,17 +64,16 @@ pub fn cli() -> Command {
6764
.value_name("CRATE_NAME")
6865
.help("Crate name that you want to manage the owner"),
6966
]),
70-
),
71-
for_subcommand_add_arg(
72-
Command::new("list")
73-
.about("List owners of a crate")
74-
.arg_quiet()
75-
.arg(
76-
Arg::new("crate")
77-
.value_name("CRATE_NAME")
78-
.help("Crate name which you want to list all owner names"),
79-
),
80-
),
67+
)
68+
.override_usage("cargo owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]"),
69+
add_registry_args(
70+
Command::new("list").about("List owners of a crate").arg(
71+
Arg::new("crate")
72+
.value_name("CRATE_NAME")
73+
.help("Crate name which you want to list all owner names"),
74+
),
75+
)
76+
.override_usage("cargo owner list [CRATE_NAME] [OPTIONS]"),
8177
])
8278
.arg_index("Registry index URL to modify owners for")
8379
.arg_registry("Registry to modify owners for")
@@ -87,7 +83,7 @@ pub fn cli() -> Command {
8783
))
8884
}
8985

90-
fn for_subcommand_add_arg(command: Command) -> Command {
86+
fn add_registry_args(command: Command) -> Command {
9187
command
9288
.arg_index("Registry index URL to modify owners for")
9389
.arg_registry("Registry to modify owners for")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use cargo_test_support::curr_dir;
2+
use cargo_test_support::prelude::*;
3+
4+
#[cargo_test]
5+
fn case() {
6+
snapbox::cmd::Command::cargo_ui()
7+
.arg("owner")
8+
.arg("add")
9+
.arg("--help")
10+
.assert()
11+
.success()
12+
.stdout_matches_path(curr_dir!().join("stdout.log"))
13+
.stderr_matches_path(curr_dir!().join("stderr.log"));
14+
}

tests/testsuite/cargo_owner/add_help/stderr.log

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Name of a user or team to invite as an owner
2+
3+
Usage: cargo owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS]
4+
5+
Arguments:
6+
<OWNER_NAME> Name of the owner you want to invite
7+
[CRATE_NAME] Crate name that you want to manage the owner
8+
9+
Options:
10+
--index <INDEX> Registry index URL to modify owners for
11+
--registry <REGISTRY> Registry to modify owners for
12+
--token <TOKEN> API token to use when authenticating
13+
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
14+
--color <WHEN> Coloring: auto, always, never
15+
--config <KEY=VALUE> Override a configuration value
16+
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
17+
-h, --help Print help
18+
19+
Manifest Options:
20+
--frozen Require Cargo.lock and cache are up to date
21+
--locked Require Cargo.lock is up to date
22+
--offline Run without accessing the network

tests/testsuite/cargo_owner/help/stdout.log

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Manage the owners of a crate on the registry
22

3-
Usage: cargo owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS]
4-
cargo owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]
5-
cargo owner list [CRATE_NAME] [OPTIONS]
3+
Usage: cargo[EXE] owner add <OWNER_NAME> [CRATE_NAME] [OPTIONS]
4+
cargo[EXE] owner remove <OWNER_NAME> [CRATE_NAME] [OPTIONS]
5+
cargo[EXE] owner list [CRATE_NAME] [OPTIONS]
66

77
Commands:
88
add Name of a user or team to invite as an owner
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use cargo_test_support::curr_dir;
2+
use cargo_test_support::prelude::*;
3+
4+
#[cargo_test]
5+
fn case() {
6+
snapbox::cmd::Command::cargo_ui()
7+
.arg("owner")
8+
.arg("list")
9+
.arg("--help")
10+
.assert()
11+
.success()
12+
.stdout_matches_path(curr_dir!().join("stdout.log"))
13+
.stderr_matches_path(curr_dir!().join("stderr.log"));
14+
}

tests/testsuite/cargo_owner/list_help/stderr.log

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
List owners of a crate
2+
3+
Usage: cargo owner list [CRATE_NAME] [OPTIONS]
4+
5+
Arguments:
6+
[CRATE_NAME] Crate name which you want to list all owner names
7+
8+
Options:
9+
--index <INDEX> Registry index URL to modify owners for
10+
--registry <REGISTRY> Registry to modify owners for
11+
--token <TOKEN> API token to use when authenticating
12+
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
13+
--color <WHEN> Coloring: auto, always, never
14+
--config <KEY=VALUE> Override a configuration value
15+
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
16+
-h, --help Print help
17+
18+
Manifest Options:
19+
--frozen Require Cargo.lock and cache are up to date
20+
--locked Require Cargo.lock is up to date
21+
--offline Run without accessing the network

tests/testsuite/cargo_owner/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
mod add_help;
12
mod help;
3+
mod list_help;
4+
mod remove_help;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use cargo_test_support::curr_dir;
2+
use cargo_test_support::prelude::*;
3+
4+
#[cargo_test]
5+
fn case() {
6+
snapbox::cmd::Command::cargo_ui()
7+
.arg("owner")
8+
.arg("remove")
9+
.arg("--help")
10+
.assert()
11+
.success()
12+
.stdout_matches_path(curr_dir!().join("stdout.log"))
13+
.stderr_matches_path(curr_dir!().join("stderr.log"));
14+
}

0 commit comments

Comments
 (0)