This commit is contained in:
2023-02-08 22:58:50 +01:00
parent 1af68a1a74
commit 7fb3e350b5
6 changed files with 128 additions and 1 deletions

View File

@@ -1,3 +1,6 @@
//! This module contains all functions related to the CLI part of the program.
//!
//! It manages and validates flags, mostly.
use std::ffi::OsString;
use std::path::PathBuf;
use std::process::exit;
@@ -55,6 +58,9 @@ pub struct Cli {
impl Cli {
/// This function prints all parts of Cli.
///
/// used for debugging.
pub fn debug_print(&self) {
debug!("complex: {}", self.complex);
debug!("colour: {}", self.colour);
@@ -75,6 +81,13 @@ impl Cli {
}
}
/// This function validates various parts of Cli.
///
/// It checks that:
/// * image exists
/// * image has the proper extension
/// * output file (if Some) does not exist
/// * map (if Some) contains ASCII-only characters
pub fn validate(&self) {
if !file_exists(&self.image) {
error!("Input file \"{}\" does not exist!", self.image.display());
@@ -101,6 +114,7 @@ impl Cli {
}
}
/// This function initializes logging (dependent on cli.debug flag)
pub fn init(&self) {
if self.debug {std::env::set_var("RUST_LOG", "trace")}
env_logger::init();