Use failure instead of error chain
This commit is contained in:
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -38,14 +38,6 @@ name = "cfg-if"
|
|||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "error-chain"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
dependencies = [
|
|
||||||
"backtrace 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "failure"
|
name = "failure"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@@ -189,7 +181,8 @@ dependencies = [
|
|||||||
name = "topgrade"
|
name = "topgrade"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"os_type 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"os_type 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"which 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@@ -257,7 +250,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
"checksum backtrace-sys 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5fd343a2466c4603f76f38de264bc0526cffc7fa38ba52fb9f13237eccc1ced2"
|
"checksum backtrace-sys 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5fd343a2466c4603f76f38de264bc0526cffc7fa38ba52fb9f13237eccc1ced2"
|
||||||
"checksum cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "49ec142f5768efb5b7622aebc3fdbdbb8950a4b9ba996393cb76ef7466e8747d"
|
"checksum cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "49ec142f5768efb5b7622aebc3fdbdbb8950a4b9ba996393cb76ef7466e8747d"
|
||||||
"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
|
"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
|
||||||
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
|
|
||||||
"checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82"
|
"checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82"
|
||||||
"checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b"
|
"checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b"
|
||||||
"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739"
|
"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ exclude = ["doc/screenshot.gif"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
which = "2.0.0"
|
which = "2.0.0"
|
||||||
error-chain = "0.11.0"
|
|
||||||
os_type = "2.0.0"
|
os_type = "2.0.0"
|
||||||
termion = "1.5.1"
|
termion = "1.5.1"
|
||||||
|
failure = "0.1.1"
|
||||||
|
failure_derive = "0.1.1"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use super::error::*;
|
use failure::Error;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use which::which;
|
use which::which;
|
||||||
@@ -38,7 +38,7 @@ impl Git {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pull<P: AsRef<Path>>(&self, path: P) -> Result<()> {
|
pub fn pull<P: AsRef<Path>>(&self, path: P) -> Result<(), Error> {
|
||||||
if let Some(git) = &self.git {
|
if let Some(git) = &self.git {
|
||||||
if let Ok(mut command) = Command::new(&git)
|
if let Ok(mut command) = Command::new(&git)
|
||||||
.arg("pull")
|
.arg("pull")
|
||||||
|
|||||||
40
src/main.rs
40
src/main.rs
@@ -1,28 +1,14 @@
|
|||||||
|
extern crate failure;
|
||||||
extern crate os_type;
|
extern crate os_type;
|
||||||
extern crate which;
|
extern crate which;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate error_chain;
|
extern crate failure_derive;
|
||||||
extern crate termion;
|
extern crate termion;
|
||||||
|
|
||||||
mod error {
|
|
||||||
error_chain!{
|
|
||||||
foreign_links {
|
|
||||||
Io(::std::io::Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
errors {
|
|
||||||
ProcessFailed {
|
|
||||||
description("Process failed")
|
|
||||||
display("Process failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod git;
|
mod git;
|
||||||
mod terminal;
|
mod terminal;
|
||||||
|
|
||||||
use error::*;
|
use failure::Error;
|
||||||
use git::Git;
|
use git::Git;
|
||||||
use os_type::OSType;
|
use os_type::OSType;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
@@ -32,16 +18,20 @@ use std::process::{Command, ExitStatus};
|
|||||||
use terminal::Terminal;
|
use terminal::Terminal;
|
||||||
use which::which;
|
use which::which;
|
||||||
|
|
||||||
|
#[derive(Fail, Debug)]
|
||||||
|
#[fail(display = "Process failed")]
|
||||||
|
struct ProcessFailed;
|
||||||
|
|
||||||
trait Check {
|
trait Check {
|
||||||
fn check(self) -> Result<()>;
|
fn check(self) -> Result<(), Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Check for ExitStatus {
|
impl Check for ExitStatus {
|
||||||
fn check(self) -> Result<()> {
|
fn check(self) -> Result<(), Error> {
|
||||||
if self.success() {
|
if self.success() {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(ErrorKind::ProcessFailed.into())
|
Err(Error::from(ProcessFailed {}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,7 +58,7 @@ fn tpm() -> Option<PathBuf> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run() -> Result<()> {
|
fn main() -> Result<(), Error> {
|
||||||
let git = Git::new();
|
let git = Git::new();
|
||||||
let mut git_repos: HashSet<String> = HashSet::new();
|
let mut git_repos: HashSet<String> = HashSet::new();
|
||||||
let terminal = Terminal::new();
|
let terminal = Terminal::new();
|
||||||
@@ -177,7 +167,7 @@ fn run() -> Result<()> {
|
|||||||
.args(&["apt", "dist-upgrade"])
|
.args(&["apt", "dist-upgrade"])
|
||||||
.spawn()?
|
.spawn()?
|
||||||
.wait()
|
.wait()
|
||||||
.map_err(|e| e.into())
|
.map_err(Error::from)
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,7 +193,7 @@ fn run() -> Result<()> {
|
|||||||
.arg("get-updates")
|
.arg("get-updates")
|
||||||
.spawn()?
|
.spawn()?
|
||||||
.wait()
|
.wait()
|
||||||
.map_err(|e| e.into())
|
.map_err(Error::from)
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +218,7 @@ fn run() -> Result<()> {
|
|||||||
.arg("upgrade")
|
.arg("upgrade")
|
||||||
.spawn()?
|
.spawn()?
|
||||||
.wait()
|
.wait()
|
||||||
.map_err(|e| e.into())
|
.map_err(Error::from)
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,5 +231,3 @@ fn run() -> Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
quick_main!(run);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user