From: Aleksey Kladov Date: Sat, 10 Mar 2018 14:08:39 +0000 (+0300) Subject: Move `index` & `registry` to `ArgMatchesExt` X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~2^2~47^2~7 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=4fac2fbb561def00db5e055346c5c3362c9cd4c9;p=cargo.git Move `index` & `registry` to `ArgMatchesExt` --- diff --git a/src/bin/cli.rs b/src/bin/cli.rs index 7c8e5b31b..7e5c45538 100644 --- a/src/bin/cli.rs +++ b/src/bin/cli.rs @@ -242,7 +242,7 @@ fn execute_subcommand(config: &mut Config, args: ArgMatches) -> CliResult { Ok(()) } ("login", Some(args)) => { - let registry = registry_from_args(config, args)?; + let registry = args.registry(config)?; let token = match args.value_of("token") { Some(token) => token.to_string(), @@ -308,7 +308,7 @@ fn execute_subcommand(config: &mut Config, args: ArgMatches) -> CliResult { Ok(()) } ("owner", Some(args)) => { - let registry = registry_from_args(config, args)?; + let registry = args.registry(config)?; let opts = ops::OwnersOptions { krate: args.value_of("crate").map(|s| s.to_string()), token: args.value_of("token").map(|s| s.to_string()), @@ -345,9 +345,9 @@ fn execute_subcommand(config: &mut Config, args: ArgMatches) -> CliResult { Ok(()) } ("publish", Some(args)) => { - let registry = registry_from_args(config, args)?; + let registry = args.registry(config)?; let ws = args.workspace(config)?; - let index = index_from_args(config, args)?; + let index = args.index(config)?; ops::publish(&ws, &ops::PublishOpts { config, @@ -435,8 +435,8 @@ fn execute_subcommand(config: &mut Config, args: ArgMatches) -> CliResult { Ok(()) } ("search", Some(args)) => { - let registry = registry_from_args(config, args)?; - let index = index_from_args(config, args)?; + let registry = args.registry(config)?; + let index = args.index(config)?; let limit: Option = args.value_of("limit") .and_then(|v| v.parse().ok()); //FIXME: validation let limit = min(100, limit.unwrap_or(10)); @@ -535,7 +535,7 @@ fn execute_subcommand(config: &mut Config, args: ArgMatches) -> CliResult { Ok(()) } ("yank", Some(args)) => { - let registry = registry_from_args(config, args)?; + let registry = args.registry(config)?; ops::yank(config, args.value_of("crate").map(|s| s.to_string()), diff --git a/src/bin/command_prelude.rs b/src/bin/command_prelude.rs index a51be4a0b..569c8423b 100644 --- a/src/bin/command_prelude.rs +++ b/src/bin/command_prelude.rs @@ -270,6 +270,45 @@ pub trait ArgMatchesExt { self._value_of("name").map(|s| s.to_string())) } + fn registry(&self, config: &Config) -> CargoResult> { + match self._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), + } + } + + fn index(&self, config: &Config) -> CargoResult> { + // TODO: Deprecated + // remove once it has been decided --host can be removed + // We may instead want to repurpose the host flag, as + // mentioned in this issue + // https://github.com/rust-lang/cargo/issues/4208 + let msg = "The flag '--host' is no longer valid. + +Previous versions of Cargo accepted this flag, but it is being +deprecated. The flag is being renamed to 'index', as the flag +wants the location of the index. Please use '--index' instead. + +This will soon become a hard error, so it's either recommended +to update to a fixed version or contact the upstream maintainer +about this warning."; + + let index = match self._value_of("host") { + Some(host) => { + config.shell().warn(&msg)?; + Some(host.to_string()) + } + None => self._value_of("index").map(|s| s.to_string()) + }; + Ok(index) + } + fn _value_of(&self, name: &str) -> Option<&str>; fn _values_of(&self, name: &str) -> Vec; @@ -298,42 +337,3 @@ pub fn values(args: &ArgMatches, name: &str) -> Vec { .map(|s| s.to_string()) .collect() } - -pub 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), - } -} - -pub fn index_from_args(config: &Config, args: &ArgMatches) -> CargoResult> { - // TODO: Deprecated - // remove once it has been decided --host can be removed - // We may instead want to repurpose the host flag, as - // mentioned in this issue - // https://github.com/rust-lang/cargo/issues/4208 - let msg = "The flag '--host' is no longer valid. - -Previous versions of Cargo accepted this flag, but it is being -deprecated. The flag is being renamed to 'index', as the flag -wants the location of the index. Please use '--index' instead. - -This will soon become a hard error, so it's either recommended -to update to a fixed version or contact the upstream maintainer -about this warning."; - - let index = match args.value_of("host") { - Some(host) => { - config.shell().warn(&msg)?; - Some(host.to_string()) - } - None => args.value_of("index").map(|s| s.to_string()) - }; - Ok(index) -}