From 0f82507ec16a60a0138de35cce7fcd2c211b8699 Mon Sep 17 00:00:00 2001 From: Chris Swindle Date: Mon, 30 Oct 2017 20:56:23 +0000 Subject: [PATCH] Adding unstable-options flag to feature gate the use of --registry option. --- src/bin/login.rs | 7 ++++++- src/bin/owner.rs | 7 ++++++- src/bin/publish.rs | 5 ++++- src/bin/search.rs | 6 +++++- src/bin/yank.rs | 7 ++++++- src/cargo/core/features.rs | 2 ++ tests/alt-registry.rs | 9 ++++----- tests/login.rs | 10 +++++----- 8 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/bin/login.rs b/src/bin/login.rs index d55176ca9..a771d7453 100755 --- a/src/bin/login.rs +++ b/src/bin/login.rs @@ -4,7 +4,7 @@ use std::io; use cargo::ops; use cargo::core::{SourceId, Source}; use cargo::sources::RegistrySource; -use cargo::util::{CliResult, CargoResultExt, Config}; +use cargo::util::{CargoError, CliResult, CargoResultExt, Config}; #[derive(Deserialize)] pub struct Options { @@ -46,6 +46,11 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { options.flag_frozen, options.flag_locked, &options.flag_z)?; + + if options.flag_registry.is_some() && !config.cli_unstable().unstable_options { + return Err(CargoError::from("registry option is an unstable feature and requires -Zunstable-options to use.").into()); + } + let token = match options.arg_token { Some(token) => token, None => { diff --git a/src/bin/owner.rs b/src/bin/owner.rs index e5d5e3530..466d56597 100644 --- a/src/bin/owner.rs +++ b/src/bin/owner.rs @@ -1,5 +1,5 @@ use cargo::ops; -use cargo::util::{CliResult, Config}; +use cargo::util::{CargoError, CliResult, Config}; #[derive(Deserialize)] pub struct Options { @@ -65,6 +65,11 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { list: options.flag_list, registry: options.flag_registry, }; + + if opts.registry.is_some() && !config.cli_unstable().unstable_options { + return Err(CargoError::from("registry option is an unstable feature and requires -Zunstable-options to use.").into()); + } + ops::modify_owners(config, &opts)?; Ok(()) } diff --git a/src/bin/publish.rs b/src/bin/publish.rs index b29ed9155..6b574cb7f 100644 --- a/src/bin/publish.rs +++ b/src/bin/publish.rs @@ -1,6 +1,6 @@ use cargo::core::Workspace; use cargo::ops; -use cargo::util::{CliResult, Config}; +use cargo::util::{CargoError, CliResult, Config}; use cargo::util::important_paths::find_root_manifest_for_wd; #[derive(Deserialize)] @@ -73,6 +73,9 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { .. } = options; + if registry.is_some() && !config.cli_unstable().unstable_options { + return Err(CargoError::from("registry option is an unstable feature and requires -Zunstable-options to use.").into()); + } // TODO: Deprecated // remove once it has been decided --host can be removed diff --git a/src/bin/search.rs b/src/bin/search.rs index 8392f9af6..70b38ecfb 100644 --- a/src/bin/search.rs +++ b/src/bin/search.rs @@ -1,5 +1,5 @@ use cargo::ops; -use cargo::util::{CliResult, Config}; +use cargo::util::{CargoError, CliResult, Config}; use std::cmp; @@ -56,6 +56,10 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { .. } = options; + if registry.is_some() && !config.cli_unstable().unstable_options { + return Err(CargoError::from("registry option is an unstable feature and requires -Zunstable-options to use.").into()); + } + // TODO: Depricated // remove once it has been decided --host can be safely removed // We may instead want to repurpose the host flag, as diff --git a/src/bin/yank.rs b/src/bin/yank.rs index 8ddf52421..64eb3a04c 100644 --- a/src/bin/yank.rs +++ b/src/bin/yank.rs @@ -1,5 +1,5 @@ use cargo::ops; -use cargo::util::{CliResult, Config}; +use cargo::util::{CargoError, CliResult, Config}; #[derive(Deserialize)] pub struct Options { @@ -54,6 +54,11 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { options.flag_frozen, options.flag_locked, &options.flag_z)?; + + if options.flag_registry.is_some() && !config.cli_unstable().unstable_options { + return Err(CargoError::from("registry option is an unstable feature and requires -Zunstable-options to use.").into()); + } + ops::yank(config, options.arg_crate, options.flag_vers, diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index d4e91c010..4cb5ac5e4 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -231,6 +231,7 @@ impl Features { #[derive(Default, Debug)] pub struct CliUnstable { pub print_im_a_teapot: bool, + pub unstable_options: bool, } impl CliUnstable { @@ -260,6 +261,7 @@ impl CliUnstable { match k { "print-im-a-teapot" => self.print_im_a_teapot = parse_bool(v)?, + "unstable-options" => self.unstable_options = true, _ => bail!("unknown `-Z` flag specified: {}", k), } diff --git a/tests/alt-registry.rs b/tests/alt-registry.rs index c6c6b3ee7..c7b937d89 100755 --- a/tests/alt-registry.rs +++ b/tests/alt-registry.rs @@ -1,4 +1,3 @@ -#[macro_use] extern crate cargotest; extern crate hamcrest; @@ -280,7 +279,7 @@ fn block_publish_due_to_no_token() { // Now perform the actual publish assert_that(p.cargo("publish").masquerade_as_nightly_cargo() - .arg("--registry").arg("alternative"), + .arg("--registry").arg("alternative").arg("-Zunstable-options"), execs().with_status(101)); } @@ -300,12 +299,12 @@ fn publish_to_alt_registry() { Package::new("bar", "0.0.1").alternative(true).publish(); // Login so that we have the token available - assert_that(p.cargo("login") - .arg("--registry").arg("alternative").arg("TOKEN"), + assert_that(p.cargo("login").masquerade_as_nightly_cargo() + .arg("--registry").arg("alternative").arg("TOKEN").arg("-Zunstable-options"), execs().with_status(0)); // Now perform the actual publish assert_that(p.cargo("publish").masquerade_as_nightly_cargo() - .arg("--registry").arg("alternative"), + .arg("--registry").arg("alternative").arg("-Zunstable-options"), execs().with_status(0)); } diff --git a/tests/login.rs b/tests/login.rs index 5e6f56192..b35c72a61 100755 --- a/tests/login.rs +++ b/tests/login.rs @@ -7,7 +7,7 @@ extern crate toml; use std::io::prelude::*; use std::fs::{self, File}; -use cargotest::cargo_process; +use cargotest::{ChannelChanger, cargo_process}; use cargotest::support::execs; use cargotest::support::registry::registry; use cargotest::install::cargo_home; @@ -157,8 +157,8 @@ fn registry_credentials() { let reg = "test-reg"; - assert_that(cargo_process().arg("login") - .arg("--registry").arg(reg).arg(TOKEN), + assert_that(cargo_process().arg("login").masquerade_as_nightly_cargo() + .arg("--registry").arg(reg).arg(TOKEN).arg("-Zunstable-options"), execs().with_status(0)); // Ensure that we have not updated the default token @@ -175,8 +175,8 @@ fn registry_credentials_with_dots() { let reg = "test.reg"; - assert_that(cargo_process().arg("login") - .arg("--registry").arg(reg).arg(TOKEN), + assert_that(cargo_process().arg("login").masquerade_as_nightly_cargo() + .arg("--registry").arg(reg).arg(TOKEN).arg("-Zunstable-options"), execs().with_status(0)); // Ensure that we have not updated the default token -- 2.30.2