Adding unstable-options flag to feature gate the use of --registry option.
authorChris Swindle <christopher.swindle@metaswitch.com>
Mon, 30 Oct 2017 20:56:23 +0000 (20:56 +0000)
committerChris Swindle <christopher.swindle@metaswitch.com>
Mon, 30 Oct 2017 20:56:23 +0000 (20:56 +0000)
src/bin/login.rs
src/bin/owner.rs
src/bin/publish.rs
src/bin/search.rs
src/bin/yank.rs
src/cargo/core/features.rs
tests/alt-registry.rs
tests/login.rs

index d55176ca9db082b83bf6d96786b59527b42ed738..a771d745348bef4581a2990e4117dc8f34bb8887 100755 (executable)
@@ -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 => {
index e5d5e3530fee077e77dbfcdc3bcaa664a578725f..466d565975e5313b6ffeabdf60a913fc5cf5cb79 100644 (file)
@@ -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(())
 }
index b29ed9155ae0f9242817f07000bd050211ae3bb5..6b574cb7f5cc4ab6a1b6628909944a5a2432c886 100644 (file)
@@ -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
index 8392f9af6c3555f8d1b4dfb82be5b60d290b03fa..70b38ecfbfd8a6d22b1b8282141538bea217ee71 100644 (file)
@@ -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
index 8ddf524218225dcbd4ba6f49d9b4363b099aa3cd..64eb3a04c5b9efedd5990739712bef21d93947bf 100644 (file)
@@ -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,
index d4e91c010133511bd54a0c08f969dd090e5e216b..4cb5ac5e44b09d92fc0dcd27d821638fad20d1b3 100644 (file)
@@ -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),
         }
 
index c6c6b3ee72560098ea0700e7b35b1cbac945cf47..c7b937d8915bc783973bb209fa45e6cda8bc0150 100755 (executable)
@@ -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));
 }
index 5e6f56192cb04e8b015ffedac8b4a6413880971f..b35c72a619fee440dd3129ea5a62e83b520a9240 100755 (executable)
@@ -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