1
0
Fork 0
mirror of https://github.com/lise-henry/crowbook synced 2024-05-23 17:26:14 +02:00

Add --no-fancy option

This commit is contained in:
Elisabeth Henry 2017-10-06 01:08:52 +02:00
parent dbb646562c
commit c9d2755119
2 changed files with 16 additions and 7 deletions

View File

@ -157,6 +157,7 @@ pub fn create_matches<'a>() -> (ArgMatches<'a>, String, String) {
static ref LANG: String = lformat!("Set the runtime language used by Crowbook");
static ref TO: String = lformat!("Generate specific format");
static ref SET: String = lformat!("Set a list of book options");
static ref NO_FANCY: String = lformat!("Disably fancy UI");
static ref LIST_OPTIONS: String = lformat!("List all possible options");
static ref LIST_OPTIONS_MD: String = lformat!("List all possible options, formatted in Markdown");
static ref PRINT_TEMPLATE: String = lformat!("Prints the default content of a template");
@ -188,6 +189,7 @@ ARGS:
.setting(AppSettings::HidePossibleValuesInHelp)
.about(ABOUT.as_str())
.arg(Arg::from_usage("-s, --single").help(SINGLE.as_str()))
.arg(Arg::from_usage("-n, --no-fancy").help(NO_FANCY.as_str()))
.arg(Arg::from_usage("-v, --verbose").help(VERBOSE.as_str()))
.arg(Arg::from_usage("-q, --quiet")
.help(QUIET.as_str())

View File

@ -80,6 +80,8 @@ pub fn try_main() -> Result<()> {
}
}
let mut fancy_ui = true;
let (matches, help, version) = create_matches();
if matches.is_present("list-options") {
@ -87,6 +89,10 @@ pub fn try_main() -> Result<()> {
exit(0);
}
if matches.is_present("no-fancy") {
fancy_ui = false;
}
if matches.is_present("list-options-md") {
println!("{}", BookOptions::description(true));
exit(0);
@ -136,24 +142,25 @@ pub fn try_main() -> Result<()> {
log_config.target = None;
log_config.location = None;
log_config.time = None;
let mut pb = false;
let verbosity = if matches.is_present("verbose") {
log_config.time = Some(LogLevel::Error);
log_config.target = Some(LogLevel::Error);
fancy_ui = false;
LogLevelFilter::Debug
} else if matches.is_present("quiet") {
fancy_ui = false;
LogLevelFilter::Error
} else if fancy_ui {
LogLevelFilter::Error
} else {
pb = true;
LogLevelFilter::Error
LogLevelFilter::Info
};
let error_dir = TempDir::new("crowbook").unwrap();
let error_path = "error.log";
if true {
if fancy_ui {
let errors = File::create(error_dir.path().join(error_path)).unwrap();
log_config.level = None;
let _ = WriteLogger::init(verbosity, log_config, errors);
} else {
if TermLogger::init(verbosity, log_config).is_err() {
@ -164,7 +171,7 @@ pub fn try_main() -> Result<()> {
{
let mut book = Book::new();
if pb {
if fancy_ui {
book.add_progress_bar();
}
book.set_options(&get_book_options(&matches));
@ -205,7 +212,7 @@ pub fn try_main() -> Result<()> {
book.render_all();
}
}
if true {
if fancy_ui {
let mut errors = String::new();
let mut file = File::open(error_dir.path().join(error_path)).unwrap();
file.read_to_string(&mut errors).unwrap();