This commit allows us to have a global progress bar to write data to giving us the following benefits: - Consistent ways to handle types of messages such as errors and warnings - Easy interface to add progress bars of various types - Easy to maintain, add new types of bars, or more while encapsulating the login in a single modulemaster
parent
40c98867b3
commit
aa629b320c
@ -1,31 +1,22 @@ |
|||||||
use console::style; |
use console::style; |
||||||
use failure::Error; |
use failure::Error; |
||||||
use indicatif::MultiProgress; |
|
||||||
use std::fs; |
use std::fs; |
||||||
|
|
||||||
|
use PBAR; |
||||||
use emoji; |
use emoji; |
||||||
use progressbar; |
|
||||||
|
|
||||||
pub fn copy_from_crate(path: &str) -> Result<(), Error> { |
pub fn copy_from_crate(path: &str) -> Result<(), Error> { |
||||||
let m = MultiProgress::new(); |
|
||||||
let step = format!( |
let step = format!( |
||||||
"{} {}Copying over your README...", |
"{} {}Copying over your README...", |
||||||
style("[5/7]").bold().dim(), |
style("[5/7]").bold().dim(), |
||||||
emoji::DANCERS |
emoji::DANCERS |
||||||
); |
); |
||||||
let pb = m.add(progressbar::new(step)); |
let pb = PBAR.message(&step); |
||||||
let crate_readme_path = format!("{}/README.md", path); |
let crate_readme_path = format!("{}/README.md", path); |
||||||
let new_readme_path = format!("{}/pkg/README.md", path); |
let new_readme_path = format!("{}/pkg/README.md", path); |
||||||
if let Err(_) = fs::copy(&crate_readme_path, &new_readme_path) { |
if let Err(_) = fs::copy(&crate_readme_path, &new_readme_path) { |
||||||
let warn = format!( |
PBAR.warn("origin crate has no README"); |
||||||
"{} {}: origin crate has no README", |
|
||||||
emoji::WARN, |
|
||||||
style("[WARN]").bold().dim() |
|
||||||
); |
|
||||||
let warn_pb = m.add(progressbar::new(warn)); |
|
||||||
warn_pb.finish(); |
|
||||||
}; |
}; |
||||||
pb.finish(); |
pb.finish(); |
||||||
m.join_and_clear()?; |
|
||||||
Ok(()) |
Ok(()) |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue