Updating based on review comments.

This commit is contained in:
Chris Swindle 2017-10-30 21:25:24 +00:00
parent 0f82507ec1
commit 0bda323c08
5 changed files with 10 additions and 9 deletions

View file

@ -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)?;

View 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,

View file

@ -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()) {

View 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()),
})
}

View file

@ -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() {