Updating based on review comments.
authorChris Swindle <christopher.swindle@metaswitch.com>
Mon, 30 Oct 2017 21:25:24 +0000 (21:25 +0000)
committerChris Swindle <christopher.swindle@metaswitch.com>
Mon, 30 Oct 2017 21:25:24 +0000 (21:25 +0000)
src/bin/login.rs
src/cargo/core/source/source_id.rs
src/cargo/ops/registry.rs
src/cargo/util/config.rs
tests/login.rs

index a771d745348bef4581a2990e4117dc8f34bb8887..499980c6d31ce4fe1a6e2b394dbfc3a054c8a7c5 100755 (executable)
@@ -55,8 +55,8 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult {
         Some(token) => token,
         None => {
             let host = match options.flag_registry {
-                Some(ref registry) => {
-                    config.get_registry_index(registry)?
+                Some(ref _registry) => {
+                    return Err(CargoError::from("token must be provided when --registry is provided.").into());
                 }
                 None => {
                     let src = SourceId::crates_io(config)?;
index ed34c95e6c0d0695425a925c62ffbd44c9c29aa2..955ecca2107d0dde0808d7da008b8c91cfc1aa52 100644 (file)
@@ -183,8 +183,7 @@ impl SourceId {
     }
 
     pub fn alt_registry(config: &Config, key: &str) -> CargoResult<SourceId> {
-        let index = config.get_registry_index(key)?;
-        let url = index.to_url()?;
+        let url = config.get_registry_index(key)?;
         Ok(SourceId {
             inner: Arc::new(SourceIdInner {
                 kind: Kind::Registry,
index bb3d5dda8e879def9a27f5e0a3128818d34f3603..5b127c78d6b1ceee0fd30324f6da642522170620 100755 (executable)
@@ -196,7 +196,7 @@ pub fn registry_configuration(config: &Config,
 
     let (index, token) = match registry {
         Some(registry) => {
-            let index = Some(config.get_registry_index(&registry)?);
+            let index = Some(config.get_registry_index(&registry)?.to_string());
             let table = config.get_table(&format!("registry.{}", registry))?.map(|t| t.val);
             let token = table.and_then(|table| {
                 match table.get("token".into()) {
index 47e79baab5b1d837fa5fd2780fa464fe16c5661e..5bf967b1af1e3826d831fa6401b60ec769ac9a86 100644 (file)
@@ -20,6 +20,8 @@ use toml;
 use core::shell::Verbosity;
 use core::{Shell, CliUnstable};
 use ops;
+use url::Url;
+use util::ToUrl;
 use util::Rustc;
 use util::errors::{CargoResult, CargoResultExt, CargoError, internal};
 use util::paths;
@@ -546,9 +548,9 @@ impl Config {
     }
 
     /// Gets the index for a registry.
-    pub fn get_registry_index(&self, registry: &str) -> CargoResult<String> {
+    pub fn get_registry_index(&self, registry: &str) -> CargoResult<Url> {
         Ok(match self.get_string(&format!("registries.{}.index", registry))? {
-            Some(index) => index.val,
+            Some(index) => index.val.to_url()?,
             None => return Err(CargoError::from(format!("No index found for registry: `{}`", registry)).into()),
         })
     }
index b35c72a619fee440dd3129ea5a62e83b520a9240..9aa356408961206cdf8185239a2f1b81300d80a0 100755 (executable)
@@ -22,10 +22,10 @@ const CONFIG_FILE: &str = r#"
     token = "api-token"
 
     [registries.test-reg]
-    index = "dummy_index"
+    index = "http://dummy_index/"
 
     [registries.test.reg]
-    index = "dummy_index"
+    index = "http://dummy_index/"
 "#;
 
 fn setup_old_credentials() {