Implement --update flag

This commit is contained in:
Danilo Bargen 2016-01-06 22:13:09 +01:00
commit 83e5e3622c
2 changed files with 11 additions and 4 deletions

View file

@ -60,6 +60,7 @@ To render a local file (for testing):
$ tldr --render /path/to/file.md
";
const ARCHIVE_URL: &'static str = "https://github.com/tldr-pages/tldr/archive/master.tar.gz";
#[derive(Debug, RustcDecodable)]
@ -119,8 +120,14 @@ fn main() {
// Update cache, pass through
if args.flag_update {
println!("Flag --update not yet implemented.");
process::exit(1);
let dl = Updater::new(ARCHIVE_URL);
let copied = dl.update().unwrap_or_else(|e| {
match e {
TldrError::UpdateError(msg) => println!("Could not update cache: {}", msg),
};
process::exit(1);
});
println!("Cached {} tldr pages.", copied);
}
// Render local file and exit

View file

@ -43,9 +43,9 @@ pub struct Updater {
impl Updater {
pub fn new(url: String) -> Updater {
pub fn new<S>(url: S) -> Updater where S: Into<String> {
Updater {
url: url,
url: url.into(),
}
}