-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
291 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
use std::env; | ||
use std::fs; | ||
use std::path::{PathBuf, Path}; | ||
|
||
use clap::ArgMatches; | ||
|
||
#[derive(Debug)] | ||
pub struct Config<'tu> { | ||
to_update: Option<Vec<&'tu str>>, | ||
depth: u8, | ||
pub tmp_dir: PathBuf | ||
pub verbose: bool | ||
} | ||
|
||
impl<'tu> Config<'tu> { | ||
pub fn from_matches(m: &'tu ArgMatches) -> Self { | ||
let temp_dir = env::temp_dir().join("cargo-outdated"); | ||
fs::create_dir(&temp_dir).unwrap(); | ||
Config { | ||
to_update: m.values_of("PKG"), | ||
depth: m.value_of("DEPTH").unwrap_or("1").parse().unwrap_or(1), | ||
tmp_dir: temp_dir | ||
verbose: m.is_present("verbose") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
use semver::Version; | ||
|
||
pub struct Dep { | ||
pub name: String, | ||
pub raw_ver: Option<String>, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::error::Error; | ||
use std::fmt::{Display, Formatter}; | ||
use std::fmt::Result as FmtResult; | ||
|
||
use fmt::Format; | ||
|
||
#[derive(Debug)] | ||
#[allow(dead_code)] | ||
pub enum CliError { | ||
Generic(String), | ||
FileOpen(String), | ||
TomlTableRoot, | ||
NoRootDeps, | ||
NoNonRootDeps, | ||
Unknown | ||
} | ||
|
||
// Copies clog::error::Error; | ||
impl CliError { | ||
/// Return whether this was a fatal error or not. | ||
#[allow(dead_code)] | ||
pub fn is_fatal(&self) -> bool { | ||
// For now all errors are fatal | ||
true | ||
} | ||
|
||
/// Print this error and immediately exit the program. | ||
/// | ||
/// If the error is non-fatal then the error is printed to stdout and the | ||
/// exit status will be `0`. Otherwise, when the error is fatal, the error | ||
/// is printed to stderr and the exit status will be `1`. | ||
pub fn exit(&self) -> ! { | ||
if self.is_fatal() { | ||
wlnerr!("{}", self); | ||
::std::process::exit(1) | ||
} else { | ||
println!("{}", self); | ||
::std::process::exit(0) | ||
} | ||
} | ||
} | ||
|
||
impl Display for CliError { | ||
fn fmt(&self, f: &mut Formatter) -> FmtResult { | ||
write!(f, "{} {}", Format::Error("error:"), self.description()) | ||
} | ||
} | ||
|
||
impl Error for CliError { | ||
fn description<'a>(&'a self) -> &'a str { | ||
match *self { | ||
CliError::Generic(ref d) => &*d, | ||
CliError::FileOpen(ref d) => &*d, | ||
CliError::TomlTableRoot => "couldn't find '[root]' table in Cargo.lock", | ||
CliError::NoRootDeps => "No root dependencies", | ||
CliError::NoNonRootDeps => "No non root dependencies", | ||
CliError::Unknown => "An unknown fatal error has occurred, please consider filing a bug-report!" | ||
} | ||
} | ||
|
||
fn cause(&self) -> Option<&Error> { | ||
match *self { | ||
CliError::Generic(..) => None, | ||
CliError::FileOpen(..) => None, | ||
CliError::Unknown => None, | ||
CliError::NoRootDeps => None, | ||
CliError::NoNonRootDeps => None, | ||
CliError::TomlTableRoot => None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::fmt; | ||
|
||
#[cfg(all(feature = "color", not(target_os = "windows")))] | ||
use ansi_term::Colour::{Red, Green, Yellow}; | ||
#[cfg(all(feature = "color", not(target_os = "windows")))] | ||
use ansi_term::ANSIString; | ||
|
||
#[allow(dead_code)] | ||
pub enum Format<T> { | ||
Error(T), | ||
Warning(T), | ||
Good(T), | ||
} | ||
|
||
#[cfg(all(feature = "color", not(target_os = "windows")))] | ||
impl<T: AsRef<str>> Format<T> { | ||
fn format(&self) -> ANSIString { | ||
match *self { | ||
Format::Error(ref e) => Red.bold().paint(e.as_ref()), | ||
Format::Warning(ref e) => Yellow.paint(e.as_ref()), | ||
Format::Good(ref e) => Green.paint(e.as_ref()), | ||
} | ||
} | ||
|
||
} | ||
|
||
#[cfg(all(feature = "color", not(target_os = "windows")))] | ||
impl<T: AsRef<str>> fmt::Display for Format<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", &self.format()) | ||
} | ||
} | ||
|
||
#[cfg(any(not(feature = "color"), target_os = "windows"))] | ||
impl<T: fmt::Display> Format<T> { | ||
fn format(&self) -> &T { | ||
match *self { | ||
Format::Error(ref e) => e, | ||
Format::Warning(ref e) => e, | ||
Format::Good(ref e) => e, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(any(not(feature = "color"), target_os = "windows"))] | ||
impl<T: fmt::Display> fmt::Display for Format<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", &self.format()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.