parent
f395b82680
commit
f65602fb71
|
@ -7,6 +7,7 @@ authors = ["Thomas Forgione <thomas@forgione.fr>"]
|
||||||
dirs = "1.0.4"
|
dirs = "1.0.4"
|
||||||
notify-rust = "3.4.2"
|
notify-rust = "3.4.2"
|
||||||
colored = "1.6.1"
|
colored = "1.6.1"
|
||||||
|
percent-encoding = "1.0.1"
|
||||||
hyper = "0.12.10"
|
hyper = "0.12.10"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
extern crate colored;
|
extern crate colored;
|
||||||
|
extern crate percent_encoding;
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
extern crate mars;
|
extern crate mars;
|
||||||
|
|
||||||
|
@ -7,10 +8,12 @@ use std::process::exit;
|
||||||
|
|
||||||
use colored::*;
|
use colored::*;
|
||||||
|
|
||||||
|
use percent_encoding::{percent_decode, percent_encode, DEFAULT_ENCODE_SET};
|
||||||
|
|
||||||
use hyper::Client;
|
use hyper::Client;
|
||||||
use hyper::rt::{self, Future};
|
use hyper::rt::{self, Future};
|
||||||
|
|
||||||
use mars::GeneralBuilder;
|
use mars::{GeneralBuilder, builder_arguments_from_string};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
|
@ -33,19 +36,22 @@ fn main() {
|
||||||
format!("http://localhost:1500{}?{}", current_dir, args)
|
format!("http://localhost:1500{}?{}", current_dir, args)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let url = percent_encode(url.as_bytes(), DEFAULT_ENCODE_SET).to_string();
|
||||||
let url = url.parse::<hyper::Uri>().unwrap();
|
let url = url.parse::<hyper::Uri>().unwrap();
|
||||||
rt::run(fetch_url(url));
|
rt::run(fetch_url(url));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_url(url: hyper::Uri) -> impl Future<Item=(), Error=()> {
|
fn fetch_url(uri: hyper::Uri) -> impl Future<Item=(), Error=()> {
|
||||||
let client = Client::new();
|
let client = Client::new();
|
||||||
client.get(url.clone())
|
client.get(uri.clone())
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
// If there was an error, build in client
|
// If there was an error, build in client
|
||||||
.map_err(move |_| {
|
.map_err(move |_| {
|
||||||
eprintln!("{}", "Server not listening, building in client...".bold().yellow());
|
eprintln!("{}", "Server not listening, building in client...".bold().yellow());
|
||||||
let builder = GeneralBuilder::new();
|
let builder = GeneralBuilder::new();
|
||||||
let _ = builder.build(&url);
|
let uri = percent_decode(uri.path().as_bytes()).decode_utf8().unwrap();
|
||||||
|
let (path, args) = builder_arguments_from_string(&*uri);
|
||||||
|
let _ = builder.build(&path, &args);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
25
src/lib.rs
25
src/lib.rs
|
@ -91,6 +91,19 @@ pub fn destroy<T, E>(result: Result<T, E>) -> Result<(), ()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts a string to a pair (PathBuf, Vec<String>).
|
||||||
|
pub fn builder_arguments_from_string(uri: &str) -> (PathBuf, Vec<String>) {
|
||||||
|
let split = uri.split('?').collect::<Vec<_>>();
|
||||||
|
let path = PathBuf::from(split[0]);
|
||||||
|
let args = if split.len() > 1 {
|
||||||
|
split[1].split('&').map(|x| x.to_owned()).collect()
|
||||||
|
} else {
|
||||||
|
vec![]
|
||||||
|
};
|
||||||
|
|
||||||
|
(path, args)
|
||||||
|
}
|
||||||
|
|
||||||
/// A general builders that contains many builders and can build any type of code.
|
/// A general builders that contains many builders and can build any type of code.
|
||||||
pub struct GeneralBuilder {
|
pub struct GeneralBuilder {
|
||||||
/// The path to the success icon.
|
/// The path to the success icon.
|
||||||
|
@ -150,16 +163,8 @@ impl GeneralBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Triggers a build.
|
/// Triggers a build.
|
||||||
pub fn build(&self, uri: &hyper::Uri) -> Result<(), Error> {
|
pub fn build(&self, path: &PathBuf, args: &Vec<String>) -> Result<(), Error> {
|
||||||
let path = uri.path();
|
let result = build(path, args, &self.builders);
|
||||||
|
|
||||||
let args = if let Some(query) = uri.query() {
|
|
||||||
query.split("&").map(|x| x.to_owned()).collect::<Vec<_>>()
|
|
||||||
} else {
|
|
||||||
vec![]
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = build(&PathBuf::from(path), &args, &self.builders);
|
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => self.notify_success(),
|
Ok(_) => self.notify_success(),
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
extern crate colored;
|
extern crate colored;
|
||||||
|
extern crate percent_encoding;
|
||||||
extern crate hyper;
|
extern crate hyper;
|
||||||
extern crate mars;
|
extern crate mars;
|
||||||
|
|
||||||
|
@ -7,11 +8,13 @@ use std::sync::{Mutex, Arc, mpsc};
|
||||||
|
|
||||||
use colored::*;
|
use colored::*;
|
||||||
|
|
||||||
|
use percent_encoding::percent_decode;
|
||||||
|
|
||||||
use hyper::{Body, Response, Server};
|
use hyper::{Body, Response, Server};
|
||||||
use hyper::service::service_fn_ok;
|
use hyper::service::service_fn_ok;
|
||||||
use hyper::rt::Future;
|
use hyper::rt::Future;
|
||||||
|
|
||||||
use mars::GeneralBuilder;
|
use mars::{GeneralBuilder, builder_arguments_from_string};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
|
@ -50,8 +53,11 @@ fn main() {
|
||||||
|
|
||||||
while let Some(uri) = tasks.pop() {
|
while let Some(uri) = tasks.pop() {
|
||||||
|
|
||||||
println!("{}", format!("---- STARTING BUILD ---- from {}", uri.path()).bold().green());
|
let uri = percent_decode(uri.path().as_bytes()).decode_utf8().unwrap();
|
||||||
match builder.build(&uri) {
|
let (path, args) = builder_arguments_from_string(&*uri);
|
||||||
|
|
||||||
|
println!("{}", format!("---- STARTING BUILD ---- from {}", uri).bold().green());
|
||||||
|
match builder.build(&path, &args) {
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
println!("{}", "--------- FAIL ---------".bold().red());
|
println!("{}", "--------- FAIL ---------".bold().red());
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue