Utils module
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use super::Check;
|
||||
use super::utils::Check;
|
||||
use failure::Error;
|
||||
use std::collections::HashSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::terminal::Terminal;
|
||||
use super::Check;
|
||||
use super::utils::Check;
|
||||
use failure;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
43
src/main.rs
43
src/main.rs
@@ -19,6 +19,7 @@ mod npm;
|
||||
mod report;
|
||||
mod steps;
|
||||
mod terminal;
|
||||
mod utils;
|
||||
mod vim;
|
||||
|
||||
use clap::App;
|
||||
@@ -27,53 +28,17 @@ use failure::Error;
|
||||
use git::{Git, Repositories};
|
||||
use report::{Report, Reporter};
|
||||
use std::env::home_dir;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{exit, ExitStatus};
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
use steps::*;
|
||||
use terminal::Terminal;
|
||||
use utils::{home_path, is_ancestor};
|
||||
use which::which;
|
||||
|
||||
#[derive(Fail, Debug)]
|
||||
#[fail(display = "Process failed")]
|
||||
struct ProcessFailed;
|
||||
|
||||
#[derive(Fail, Debug)]
|
||||
#[fail(display = "A step failed")]
|
||||
struct StepFailed;
|
||||
|
||||
trait Check {
|
||||
fn check(self) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
impl Check for ExitStatus {
|
||||
fn check(self) -> Result<(), Error> {
|
||||
if self.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::from(ProcessFailed {}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn home_path(p: &str) -> PathBuf {
|
||||
let mut path = home_dir().unwrap();
|
||||
path.push(p);
|
||||
path
|
||||
}
|
||||
|
||||
fn is_ancestor(ancestor: &Path, path: &Path) -> bool {
|
||||
let mut p = path;
|
||||
while let Some(parent) = p.parent() {
|
||||
if parent == ancestor {
|
||||
return true;
|
||||
}
|
||||
|
||||
p = parent;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn tpm() -> Option<PathBuf> {
|
||||
let mut path = home_dir().unwrap();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::Check;
|
||||
use super::utils::Check;
|
||||
use failure;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::Check;
|
||||
use super::utils::Check;
|
||||
use failure;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
41
src/utils.rs
Normal file
41
src/utils.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use failure::Error;
|
||||
use std::env::home_dir;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::ExitStatus;
|
||||
|
||||
#[derive(Fail, Debug)]
|
||||
#[fail(display = "Process failed")]
|
||||
pub struct ProcessFailed;
|
||||
|
||||
pub trait Check {
|
||||
fn check(self) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
impl Check for ExitStatus {
|
||||
fn check(self) -> Result<(), Error> {
|
||||
if self.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::from(ProcessFailed {}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn home_path(p: &str) -> PathBuf {
|
||||
let mut path = home_dir().unwrap();
|
||||
path.push(p);
|
||||
path
|
||||
}
|
||||
|
||||
pub fn is_ancestor(ancestor: &Path, path: &Path) -> bool {
|
||||
let mut p = path;
|
||||
while let Some(parent) = p.parent() {
|
||||
if parent == ancestor {
|
||||
return true;
|
||||
}
|
||||
|
||||
p = parent;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
Reference in New Issue
Block a user