Build in client if no server

This commit is contained in:
Thomas Forgione 2018-09-25 14:58:01 +02:00
parent be1f064c4d
commit 96189faf3f
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 12 additions and 4 deletions

View File

@ -1,11 +1,17 @@
extern crate colored;
extern crate hyper;
extern crate mars;
use std::env;
use std::process::exit;
use colored::*;
use hyper::Client;
use hyper::rt::{self, Future};
use mars::GeneralBuilder;
fn main() {
let current_dir = match env::current_dir() {
@ -27,11 +33,13 @@ fn main() {
fn fetch_url(url: hyper::Uri) -> impl Future<Item=(), Error=()> {
let client = Client::new();
let path = url.path().to_owned();
client.get(url)
.map(|_| ())
// If there was an error, let the user know...
.map_err(|err| {
eprintln!("Error {}", err);
// If there was an error, build in client
.map_err(move |_| {
eprintln!("{}", "Server not listening, building in client...".bold().yellow());
let builder = GeneralBuilder::new();
let _ = builder.build(&path);
})
}