Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run rustfmt over multirust #16

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
420 changes: 216 additions & 204 deletions rust-install/src/dist.rs

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions rust-install/src/env_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ use std::process::Command;
use utils;

pub fn set_default(name: &str, value: &OsStr, cmd: &mut Command) {
let new_value = env::var_os(name)
.and_then(utils::if_not_empty)
.unwrap_or(value.to_owned());
cmd.env(name, new_value);
let new_value = env::var_os(name)
.and_then(utils::if_not_empty)
.unwrap_or(value.to_owned());
cmd.env(name, new_value);
}

pub fn set_path(name: &str, value: &Path, cmd: &mut Command) {
let old_value = env::var_os(name);
let mut parts = vec![value.to_owned()];
if let Some(ref v) = old_value {
parts.extend(env::split_paths(v));
}
let new_value = env::join_paths(parts).unwrap_or_else(|_| OsString::from(value));
cmd.env(name, new_value);
let old_value = env::var_os(name);
let mut parts = vec![value.to_owned()];
if let Some(ref v) = old_value {
parts.extend(env::split_paths(v));
}
let new_value = env::join_paths(parts).unwrap_or_else(|_| OsString::from(value));

cmd.env(name, new_value);
}
133 changes: 68 additions & 65 deletions rust-install/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@ use utils;
use notify::{NotificationLevel, Notifyable};

pub enum Notification<'a> {
Utils(utils::Notification<'a>),
Temp(temp::Notification<'a>),
Extracting(&'a Path, &'a Path),
UpdateHashMatches(&'a str),
CantReadUpdateHash(&'a Path),
NoUpdateHash(&'a Path),
ChecksumValid(&'a str),
Utils(utils::Notification<'a>),
Temp(temp::Notification<'a>),

Extracting(&'a Path, &'a Path),
UpdateHashMatches(&'a str),
CantReadUpdateHash(&'a Path),
NoUpdateHash(&'a Path),
ChecksumValid(&'a str),
}

pub enum Error {
Utils(utils::Error),
Temp(temp::Error),

InvalidFileExtension,
InvalidInstaller,
InvalidToolchainName,
NotInstalledHere,
InstallTypeNotPossible,
UnsupportedHost(String),
ChecksumFailed { url: String, expected: String, calculated: String },
Utils(utils::Error),
Temp(temp::Error),

InvalidFileExtension,
InvalidInstaller,
InvalidToolchainName,
NotInstalledHere,
InstallTypeNotPossible,
UnsupportedHost(String),
ChecksumFailed {
url: String,
expected: String,
calculated: String,
},
}

pub type Result<T> = ::std::result::Result<T, Error>;
Expand All @@ -40,57 +44,56 @@ extend_notification!(Notification: utils::Notification, n => Notification::Utils
extend_notification!(Notification: temp::Notification, n => Notification::Temp(n));

impl<'a> Notification<'a> {
pub fn level(&self) -> NotificationLevel {
use self::Notification::*;
match *self {
Temp(ref n) => n.level(),
Utils(ref n) => n.level(),
NoUpdateHash(_) =>
NotificationLevel::Verbose,
Extracting(_, _) | ChecksumValid(_) =>
NotificationLevel::Normal,
UpdateHashMatches(_) =>
NotificationLevel::Info,
CantReadUpdateHash(_) =>
NotificationLevel::Warn,
}
}
pub fn level(&self) -> NotificationLevel {
use self::Notification::*;
match *self {
Temp(ref n) => n.level(),
Utils(ref n) => n.level(),
NoUpdateHash(_) => NotificationLevel::Verbose,
Extracting(_, _) | ChecksumValid(_) => NotificationLevel::Normal,
UpdateHashMatches(_) => NotificationLevel::Info,
CantReadUpdateHash(_) => NotificationLevel::Warn,
}
}
}

impl<'a> Display for Notification<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> {
use self::Notification::*;
match *self {
Temp(ref n) => n.fmt(f),
Utils(ref n) => n.fmt(f),
Extracting(_, _) =>
write!(f, "extracting..."),
UpdateHashMatches(hash) =>
write!(f, "update hash matches: {}, skipping update...", hash),
CantReadUpdateHash(path) =>
write!(f, "can't read update hash file: '{}', can't skip update...", path.display()),
NoUpdateHash(path) =>
write!(f, "no update hash at: '{}'", path.display()),
ChecksumValid(_) =>
write!(f, "checksum passed"),
}
}
fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> {
use self::Notification::*;
match *self {
Temp(ref n) => n.fmt(f),
Utils(ref n) => n.fmt(f),
Extracting(_, _) => write!(f, "extracting..."),
UpdateHashMatches(hash) =>
write!(f, "update hash matches: {}, skipping update...", hash),
CantReadUpdateHash(path) =>
write!(f,
"can't read update hash file: '{}', can't skip update...",
path.display()),
NoUpdateHash(path) => write!(f, "no update hash at: '{}'", path.display()),
ChecksumValid(_) => write!(f, "checksum passed"),
}
}
}

impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> {
use self::Error::*;
match *self {
Temp(ref n) => n.fmt(f),
Utils(ref n) => n.fmt(f),
InvalidFileExtension => write!(f, "invalid file extension"),
InvalidInstaller => write!(f, "invalid installer"),
InvalidToolchainName => write!(f, "invalid custom toolchain name"),
NotInstalledHere => write!(f, "not installed here"),
InstallTypeNotPossible => write!(f, "install type not possible"),
UnsupportedHost(ref spec) => write!(f, "a binary package was not provided for: '{}'", spec),
ChecksumFailed { url: _, ref expected, ref calculated } =>
write!(f, "checksum failed, expected: '{}', calculated: '{}'", expected, calculated),
}
}
fn fmt(&self, f: &mut fmt::Formatter) -> ::std::result::Result<(), fmt::Error> {
use self::Error::*;
match *self {
Temp(ref n) => n.fmt(f),
Utils(ref n) => n.fmt(f),
InvalidFileExtension => write!(f, "invalid file extension"),
InvalidInstaller => write!(f, "invalid installer"),
InvalidToolchainName => write!(f, "invalid custom toolchain name"),
NotInstalledHere => write!(f, "not installed here"),
InstallTypeNotPossible => write!(f, "install type not possible"),
UnsupportedHost(ref spec) =>
write!(f, "a binary package was not provided for: '{}'", spec),
ChecksumFailed { url: _, ref expected, ref calculated } =>
write!(f,
"checksum failed, expected: '{}', calculated: '{}'",
expected,
calculated),
}
}
}
Loading