Skip to content
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

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
786e0b6
Support cargo owner add
heisen-li Mar 23, 2023
9bef78d
Merge remote-tracking branch 'upstream/master' into owner
heisen-li Mar 23, 2023
5862698
Delete res.txt
heisen-li Mar 23, 2023
8914b1a
Update registry.rs
heisen-li Mar 23, 2023
6573a9e
Merge branch 'rust-lang:master' into owner
heisen-li Apr 2, 2023
baf3020
Added test cases and modified document descriptions.
heisen-li Apr 2, 2023
0ae910a
Merge remote-tracking branch 'upstream/owner' into owner
heisen-li Apr 2, 2023
efaf17b
fix doc
heisen-li Apr 2, 2023
6037751
Merge branch 'rust-lang:master' into owner
heisen-li Apr 3, 2023
3a99929
fix some problem
heisen-li Apr 4, 2023
1423140
Merge remote-tracking branch 'upstream/owner' into owner
heisen-li Apr 4, 2023
a2a59ea
Revised based on review comments
heisen-li Apr 4, 2023
08be20f
Use enumerate and move parameters to subcommands
heisen-li Apr 10, 2023
e038e62
fix
heisen-li Apr 16, 2023
21afbcf
fix
heisen-li Apr 16, 2023
1ef930f
Remove some test cases.
heisen-li Apr 16, 2023
a8b46be
update
heisen-li Nov 2, 2023
33ca2b8
update
heisen-li Nov 2, 2023
daaa8c1
delete file
heisen-li Nov 2, 2023
fc7987e
update tests
heisen-li Nov 2, 2023
5a988dd
Merge remote-tracking branch 'origin/owner' into owner
heisen-li Nov 2, 2023
3fc6b53
fix some error
heisen-li Nov 2, 2023
1dc82ae
add some test & fix some error
heisen-li Nov 3, 2023
415bbf6
fix conflicts
heisen-li Nov 13, 2023
60ebb2a
add doc man
heisen-li Nov 20, 2023
3fa434d
modify
heisen-li Nov 21, 2023
3678dff
Merge branch 'rust-lang:master' into owner
heisen-li Nov 23, 2023
7acc02f
fix test and some
heisen-li Nov 25, 2023
bd2f6ef
Merge branch 'owner' of https://github.com/heisen-li/cargo into owner
heisen-li Nov 25, 2023
13fccb2
fix test
heisen-li Nov 25, 2023
bf304aa
modify the code by comments
heisen-li Dec 12, 2023
97d2596
resolve conflict
heisen-li Dec 12, 2023
0987b72
resolve conflict
heisen-li Dec 12, 2023
05c1653
resolve conflict
heisen-li Dec 12, 2023
1bc57c7
Merge branch 'owner' of https://github.com/heisen-li/cargo into owner
heisen-li Dec 12, 2023
b722762
fix failed test
heisen-li Dec 12, 2023
01701f7
fix failed tests
heisen-li Dec 12, 2023
9f7e9bd
fix failed tests
heisen-li Dec 12, 2023
b01c084
Merge branch 'owner' of https://github.com/heisen-li/cargo into owner
heisen-li Dec 12, 2023
3e1914e
fix tests
heisen-li Dec 12, 2023
6d2b554
zsh completions
heisen-li Dec 20, 2023
48b5429
fix conflict
heisen-li Jan 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 114 additions & 14 deletions src/bin/cargo/commands/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
epage marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something we've not talked about is the stabilization plan.

Options

  • Insta-stable: requires us being more confident, will have an FCP in this issue for the team to agree
  • Put the subcommands behind -Zunstable-options and stabilize later
    • We'd want to keep the focus on the existing flags until the stabilization PR

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 add and remove to be dry-run by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mixed about whether cargo owner should show --help or should default to cargo owner list

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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"))
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is meant to operate for None. We should separate out Some(_) and panic for it as we should only get the subcommands back we defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are no subcommands or any parameters(like:--add,..), an error message will be displayed instead of panic.

https://github.com/rust-lang/cargo/pull/11879/files#diff-981bc8fd9f47eff85de2c539a5be58b0002e2f060064a090218060c5ae3e5722R114-R122

};

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(())
}
26 changes: 16 additions & 10 deletions src/doc/man/cargo-owner.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 }}
Expand All @@ -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}}
21 changes: 11 additions & 10 deletions src/doc/man/generated_txt/cargo-owner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)).
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 16 additions & 13 deletions src/doc/src/commands/cargo-owner.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -27,25 +27,28 @@ information about owners and publishing.

## OPTIONS

### Owner Options
### Subcommand

<dl>

<dt class="option-term" id="option-cargo-owner--a"><a class="option-anchor" href="#option-cargo-owner--a"></a><code>-a</code></dt>
<dt class="option-term" id="option-cargo-owner---add"><a class="option-anchor" href="#option-cargo-owner---add"></a><code>--add</code> <em>login</em>…</dt>
<dt class="option-term" id="option-cargo-owner-add"><a class="option-anchor" href="#option-cargo-owner-add"></a><code>add</code> <em>login</em>…</dt>
<dd class="option-desc">Invite the given user or team as an owner.</dd>


<dt class="option-term" id="option-cargo-owner--r"><a class="option-anchor" href="#option-cargo-owner--r"></a><code>-r</code></dt>
<dt class="option-term" id="option-cargo-owner---remove"><a class="option-anchor" href="#option-cargo-owner---remove"></a><code>--remove</code> <em>login</em>…</dt>
<dt class="option-term" id="option-cargo-owner-remove"><a class="option-anchor" href="#option-cargo-owner-remove"></a><code>remove</code> <em>login</em>…</dt>
<dd class="option-desc">Remove the given user or team as an owner.</dd>


<dt class="option-term" id="option-cargo-owner--l"><a class="option-anchor" href="#option-cargo-owner--l"></a><code>-l</code></dt>
<dt class="option-term" id="option-cargo-owner---list"><a class="option-anchor" href="#option-cargo-owner---list"></a><code>--list</code></dt>
<dt class="option-term" id="option-cargo-owner-list"><a class="option-anchor" href="#option-cargo-owner-list"></a><code>list</code></dt>
<dd class="option-desc">List owners of a crate.</dd>


</dl>

### Owner Options

<dl>

<dt class="option-term" id="option-cargo-owner---token"><a class="option-anchor" href="#option-cargo-owner---token"></a><code>--token</code> <em>token</em></dt>
<dd class="option-desc">API token to use when authenticating. This overrides the token stored in
the credentials file (which is created by <a href="cargo-login.html">cargo-login(1)</a>).</p>
Expand Down Expand Up @@ -162,15 +165,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)
12 changes: 6 additions & 6 deletions src/doc/src/reference/publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
epage marked this conversation as resolved.
Show resolved Hide resolved
$ 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
Expand Down
3 changes: 3 additions & 0 deletions src/etc/_cargo
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Copy link
Contributor

Choose a reason for hiding this comment

The 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 cargo report future-incompat completions for us to copy from

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to finish. In addition, whether cargo report future-incompat should be corrected in the new issue.

'--token=[specify API token to use when authenticating]:token' \
'*: :_guard "^-*" "crate"'
;;
Expand Down
Loading