Select Git revision
uc-postgresql.yaml
mod.rs 2.53 KiB
use crate::presenter;
use clap::Command;
use failure::Fail;
use std::fs;
use std::io::{Read, stdin};
use std::path::Path;
//pub mod generate_bpmn;
pub mod generate_json;
pub mod serve;
pub mod validate;
pub mod version;
#[derive(Fail, Debug)]
pub enum UJMTError {
#[fail(display = "{}", _0)]
FileInputError(FileInputError),
#[fail(display = "BPMN File could not be generated. ({})", _0)]
GenerationFailed(presenter::PresenterError),
#[fail(display = "Service could not be started. ({})", _0)]
ServeFailed(Box<dyn std::error::Error + Send + Sync>),
#[fail(display = "Version could not be printed. ({})", _0)]
VersionError(std::io::Error),
#[fail(display = "An Error Occured. ({})", _0)]
Error(String),
}
#[derive(Fail, Debug)]
pub enum FileInputError {
#[fail(display = "File \"{}\" cannot be read. ({})", _0, _1)]
FileUnreadable(String, std::io::Error),
#[fail(display = "File \"{}\" does not exist.", _0)]
FileNotFound(String)
}
pub fn exec(app: &mut Command) {
let matches = app.clone().get_matches();
// initialise logger
let mut log_level = "info";
if matches.get_flag("debugging") {
log_level = "debug";
};
let _guard = slog_scope::set_global_logger(crate::core::log::new(log_level));
debug!("Initialised Global Logger");
let res;
// exec command or print help
match matches.subcommand() {
//Some(("generate_bpmn", submatches)) => res = generate_bpmn::exec(submatches),
Some(("generate_json", submatches)) => res = generate_json::exec(submatches),
Some(("serve", submatches)) => res = serve::exec(submatches),
Some(("validate", submatches)) => res = validate::exec(submatches),
Some(("version", submatches)) => res = version::exec(submatches),
_ =>
{
app.print_help().unwrap();
res = Ok(())
}
}
if res.is_err(){
error!("{}", res.unwrap_err());
}
}
fn read(input_file: &str) -> Result<String, FileInputError> {
let mut source = String::new();
if input_file == "" {
stdin()
.read_to_string(&mut source)
.map_err(|error| FileInputError::FileUnreadable(String::from("stdin"), error))?;
} else if Path::new(input_file).exists() {
source = fs::read_to_string(input_file)
.map_err(|error| FileInputError::FileUnreadable(input_file.to_string(), error))?;
} else {
return Err(FileInputError::FileNotFound(input_file.to_string()));
}
return Ok(source);
}