Use log and beautylog
This commit is contained in:
parent
a2767ee117
commit
f7e8a96550
|
@ -1,25 +1,49 @@
|
|||
[[package]]
|
||||
name = "beautylog"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"colored 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "colored"
|
||||
version = "1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gclone"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"beautylog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"colored 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.2.0"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.4"
|
||||
|
@ -66,8 +90,11 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[metadata]
|
||||
"checksum beautylog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1457a99b95a92f1de6f3a1fe08324f200cd68e0f43b13d4289752ead6ed531a2"
|
||||
"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
|
||||
"checksum colored 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e9a455e156a4271e12fd0246238c380b1e223e3736663c7a18ed8b6362028a9"
|
||||
"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
|
||||
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
|
||||
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
|
||||
"checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
|
||||
"checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1"
|
||||
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
|
||||
|
|
|
@ -8,6 +8,8 @@ edition = "2018"
|
|||
colored = "1.7.0"
|
||||
walkdir = "2.2.7"
|
||||
lazy_static = "1.2.0"
|
||||
log = "0.4.6"
|
||||
beautylog = "0.1.0"
|
||||
|
||||
[[bin]]
|
||||
name = "gclone"
|
||||
|
|
|
@ -98,10 +98,7 @@ impl Cache {
|
|||
1 => Ok(matches[0].clone()),
|
||||
|
||||
len => {
|
||||
eprintln!(
|
||||
"{}",
|
||||
"info: multiple entries found, please select one".bold()
|
||||
);
|
||||
info!("{}", "multiple entries found, please select one");
|
||||
|
||||
for (i, j) in matches.iter().enumerate() {
|
||||
eprintln!(
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
|
||||
use colored::*;
|
||||
|
||||
use gclone::git::{clone, parse_url, GCLONE_PATH};
|
||||
use gclone::{first_arg, Cache, Result};
|
||||
|
||||
|
@ -11,6 +12,10 @@ fn help() {
|
|||
}
|
||||
|
||||
fn main_result() -> Result<()> {
|
||||
|
||||
// Init beautylog
|
||||
beautylog::init(log::LevelFilter::Info).ok();
|
||||
|
||||
// Parse args
|
||||
let url = first_arg()?;
|
||||
|
||||
|
@ -33,9 +38,9 @@ fn main_result() -> Result<()> {
|
|||
path.push(&repo);
|
||||
|
||||
// Clone repository
|
||||
eprintln!("{} {} {}{}", "info:".bold(), "cloning", url, "...");
|
||||
clone(&url, &path.display().to_string())?;
|
||||
eprintln!("{} {}", "info:".bold(), "done!");
|
||||
info!("{} {}{}", "cloning", url, "...");
|
||||
clone(&url, &path)?;
|
||||
info!("{}", "done!");
|
||||
|
||||
// Append to cache
|
||||
let mut cache = Cache::read()?;
|
||||
|
@ -47,7 +52,7 @@ fn main_result() -> Result<()> {
|
|||
|
||||
fn main() {
|
||||
if let Err(e) = main_result() {
|
||||
eprintln!("{}", e);
|
||||
error!("{}", e);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ lazy_static! {
|
|||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
let e: Error = e.into();
|
||||
eprintln!("{}", e);
|
||||
error!("couldn't read environnement variable GCLONE_PATH: {}", e);
|
||||
exit(1);
|
||||
},
|
||||
}
|
||||
|
|
59
src/lib.rs
59
src/lib.rs
|
@ -12,11 +12,12 @@
|
|||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use std::io;
|
||||
use std::{env, error, fmt, num, result};
|
||||
|
||||
use colored::*;
|
||||
|
||||
mod cache;
|
||||
pub use cache::Cache;
|
||||
|
||||
|
@ -71,68 +72,34 @@ impl fmt::Display for Error {
|
|||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Error::NoGclonePath(e) => write!(
|
||||
fmt,
|
||||
"{} {} {}",
|
||||
"error:".bold().red(),
|
||||
"couldn't read environment variable GCLONE_PATH".bold(),
|
||||
e
|
||||
fmt, "couldn't read environment variable GCLONE_PATH {}", e
|
||||
),
|
||||
Error::IoError(e) => write!(
|
||||
fmt,
|
||||
"{} {} {}",
|
||||
"error:".bold().red(),
|
||||
"couldn't read or write cache:".bold(),
|
||||
e
|
||||
fmt, "couldn't read or write cache: {}", e
|
||||
),
|
||||
Error::GitUrlParseError => write!(
|
||||
fmt,
|
||||
"{} {}",
|
||||
"error:".bold().red(),
|
||||
"couldn't guess server, owner and repo from url".bold()
|
||||
fmt, "couldn't guess server, owner and repo from url"
|
||||
),
|
||||
Error::GitCloneError(Some(e)) => write!(
|
||||
fmt,
|
||||
"{} {} {}",
|
||||
"error:".bold().red(),
|
||||
"couldn't clone git repository:".bold(),
|
||||
e
|
||||
fmt, "couldn't clone git repository: {}", e
|
||||
),
|
||||
Error::GitCloneError(None) => write!(
|
||||
fmt,
|
||||
"{} {}",
|
||||
"error:".bold().red(),
|
||||
"couldn't clone git repository".bold()
|
||||
fmt, "couldn't clone git repository"
|
||||
),
|
||||
Error::PathAlreadyExists => write!(
|
||||
fmt,
|
||||
"{} {}",
|
||||
"error:".bold().red(),
|
||||
"the path corresponding to the repository already exists".bold()
|
||||
fmt, "the path corresponding to the repository already exists"
|
||||
),
|
||||
Error::WrongArgument => write!(
|
||||
fmt,
|
||||
"{} {}",
|
||||
"error:".bold().red(),
|
||||
"this program expects exactly one argument".bold()
|
||||
fmt, "this program expects exactly one argument"
|
||||
),
|
||||
Error::ParseIntError(e) => write!(
|
||||
fmt,
|
||||
"{} {} {}",
|
||||
"error:".bold().red(),
|
||||
"couldn't parse integer:".bold(),
|
||||
e
|
||||
fmt, "couldn't parse integer: {}", e
|
||||
),
|
||||
Error::OutsideRange => write!(
|
||||
fmt,
|
||||
"{} {}",
|
||||
"error:".bold().red(),
|
||||
"integer is outside the range".bold()
|
||||
fmt, "integer is outside the range"
|
||||
),
|
||||
Error::NoSuchDirectory => write!(
|
||||
fmt,
|
||||
"{} {}",
|
||||
"error:".bold().red(),
|
||||
"no such directory was found".bold()
|
||||
fmt, "no such directory was found"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
|
16
src/pgd.rs
16
src/pgd.rs
|
@ -1,12 +1,14 @@
|
|||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
use std::process::exit;
|
||||
|
||||
use colored::*;
|
||||
|
||||
use gclone::{first_arg, Cache, Error, Result};
|
||||
|
||||
fn main() {
|
||||
beautylog::init(log::LevelFilter::Info).ok();
|
||||
|
||||
if let Err(e) = main_result() {
|
||||
eprintln!("{}", e);
|
||||
error!("{}", e);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +30,7 @@ fn main_with_cache(request: &str, regen: bool) -> Result<()> {
|
|||
|
||||
let only_match = match cache.find_interactive(&request) {
|
||||
Err(Error::NoSuchDirectory) if regen && !just_generated => {
|
||||
eprintln!(
|
||||
"{} {}",
|
||||
"warning:".bold().yellow(),
|
||||
"directory not found, regenerating cache...".bold()
|
||||
);
|
||||
warn!("directory not found, regenerating cache...");
|
||||
let cache = Cache::generate();
|
||||
cache.write()?;
|
||||
return main_with_cache(request, false);
|
||||
|
|
Loading…
Reference in New Issue