From 01d908a6939c952789e3455183dee7c0c6c37a23 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 7 Mar 2018 17:40:33 +0300 Subject: [PATCH] Move owner to clap --- src/bin/cargo.rs | 5 +++-- src/bin/cli/mod.rs | 37 ++++++++++++++++++++++++++++++++----- src/bin/cli/owner.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 src/bin/cli/owner.rs diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index ed0739c6d..a85c0e5c6 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -90,7 +90,8 @@ fn main() { let is_clapified = ::std::env::args().any(|arg| match arg.as_ref() { "build" | "bench" | "check" | "clean" | "doc" | "fetch" | "generate-lockfile" | "git-checkout" | - "init" | "install" | "locate-project" | "login" | "metadata" | "new" => true, + "init" | "install" | "locate-project" | "login" | "metadata" | "new" | + "owner" => true, _ => false }); @@ -133,7 +134,7 @@ macro_rules! each_subcommand{ // $mac!(login); // $mac!(metadata); // $mac!(new); - $mac!(owner); +// $mac!(owner); $mac!(package); $mac!(pkgid); $mac!(publish); diff --git a/src/bin/cli/mod.rs b/src/bin/cli/mod.rs index 0f40a8b15..f394b3ae8 100644 --- a/src/bin/cli/mod.rs +++ b/src/bin/cli/mod.rs @@ -129,6 +129,19 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> { args.value_of("name")) } + fn registry_from_args(config: &Config, args: &ArgMatches) -> CargoResult> { + match args.value_of("registry") { + Some(registry) => { + if !config.cli_unstable().unstable_options { + return Err(format_err!("registry option is an unstable feature and \ + requires -Zunstable-options to use.").into()); + } + Ok(Some(registry.to_string())) + } + None => Ok(None), + } + } + config_from_args(config, &args)?; match args.subcommand() { ("bench", Some(args)) => { @@ -288,11 +301,7 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> { return Ok(()); } ("login", Some(args)) => { - let registry = args.value_of("registry").map(|s| s.to_string()); - if registry.is_some() && !config.cli_unstable().unstable_options { - return Err(format_err!("registry option is an unstable feature and \ - requires -Zunstable-options to use.").into()); - } + let registry = registry_from_args(config, args)?; let token = match args.value_of("token") { Some(token) => token.to_string(), @@ -357,6 +366,22 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> { config.shell().status("Created", format!("{} `{}` project", opts.kind, path))?; Ok(()) } + ("owner", Some(args)) => { + let registry = registry_from_args(config, args)?; + let opts = ops::OwnersOptions { + krate: args.value_of("crate").map(|s| s.to_string()), + token: args.value_of("token").map(|s| s.to_string()), + index: args.value_of("index").map(|s| s.to_string()), + to_add: args.values_of("add") + .map(|xs| xs.map(|s| s.to_string()).collect()), + to_remove: args.values_of("remove") + .map(|xs| xs.map(|s| s.to_string()).collect()), + list: args.is_present("list"), + registry: args.value_of("registry").map(|s| s.to_string()), + }; + ops::modify_owners(config, &opts)?; + return Ok(()); + } _ => return Ok(()) } } @@ -440,6 +465,7 @@ See 'cargo help ' for more information on a specific command. login::cli(), metadata::cli(), new::cli(), + owner::cli(), ]) ; app @@ -462,6 +488,7 @@ mod locate_project; mod login; mod metadata; mod new; +mod owner; mod utils { use clap::{self, SubCommand, AppSettings}; diff --git a/src/bin/cli/owner.rs b/src/bin/cli/owner.rs new file mode 100644 index 000000000..a65d0f290 --- /dev/null +++ b/src/bin/cli/owner.rs @@ -0,0 +1,28 @@ +use super::utils::*; + +pub fn cli() -> App { + subcommand("owner") + .about("Manage the owners of a crate on the registry") + .arg(Arg::with_name("crate")) + .arg( + opt("add", "Name of a user or team to add as an owner") + .short("a").value_name("LOGIN").multiple(true) + ) + .arg( + opt("remove", "Name of a user or team to remove as an owner") + .short("r").value_name("LOGIN").multiple(true) + ) + .arg(opt("list", "List owners of a crate").short("l")) + .arg(opt("index", "Registry index to modify owners for").value_name("INDEX")) + .arg(opt("token", "API token to use when authenticating").value_name("TOKEN")) + .arg(opt("registry", "Registry to use").value_name("REGISTRY")) + .after_help("\ + This command will modify the owners for a package + on the specified registry(or + default).Note that owners of a package can upload new versions, yank old + versions.Explicitly named owners can also modify the set of owners, so take + caution! + + See http://doc.crates.io/crates-io.html#cargo-owner for detailed documentation + and troubleshooting.") +} -- 2.30.2