pub fn new() -> Result<Self, anyhow::Error> {
        let cli = Config::from_args();

        // TODO: This is a very simplistic method that should be improved/strengthened
        let process_name = std::env::args()
            .next()
            .unwrap()
            .split('/')
            .last()
            .unwrap()
            .to_string();

        let mut input = String::new();
        File::open(&cli.config_file)?.read_to_string(&mut input)?;
        let mut config = toml::from_str::<Self>(&input)?;

        if let Some(pid_file) = cli.pid_file {
            config.pid_file = Some(pid_file);
        } else if config.pid_file == None {
            // The PID file wasn't specified. Default to process name
            config.pid_file = Some(format!("data/{}.pid", process_name));
        }

        if let Some(log_file) = cli.log_file {
            config.log_file = Some(log_file);
        } else if config.log_file == None {
            // The log file wasn't specified. Default to process name
            config.log_file = Some(format!("logs/{}.log", process_name));
        }

        if let Some(ws_addr) = cli.ws_addr {
            config.ws_addr = Some(ws_addr);
        }

        if let Some(telnet_addr) = cli.telnet_addr {
            config.telnet_addr = Some(telnet_addr);
        }

        if let Some(mq_addr) = cli.mq_addr {
            config.mq_addr = Some(mq_addr);
        }

        config.debug = cli.debug;

        config.verbose = cli.verbose;

        Ok(config)
    }
/// Returns a new Config
/// Read configuration from the file path specified in the Clap arguments struct.
///
/// # Errors
///
/// * Returns `std::io::Error` if the config file can't be opened or read
/// * Returns `toml::de::Error` if TOML parsing fails
///
/// # Panics
///
/// TODO: add possible panics here
Returns a new Config
Read configuration from the file path specified in the Clap arguments struct.
Returns a new Config Read configuration from the file path specified in the Clap arguments struct .
pub fn new() -> Result<Self, anyhow::Error> {
        let cli = Config::from_args();
        // TODO: This is a very simplistic method that should be improved/strengthened
        let process_name = std::env::args()
            .next()
            .unwrap()
            .split('/')
            .last()
            .unwrap()
            .to_string();
        let mut input = String::new();
        File::open(&cli.config_file)?.read_to_string(&mut input)?;
        let mut config = toml::from_str::<Self>(&input)?;
        if let Some(pid_file) = cli.pid_file {
            config.pid_file = Some(pid_file);
        } else if config.pid_file == None {
            // The PID file wasn't specified. Default to process name
            config.pid_file = Some(format!("data/{}.pid", process_name));
        }
        if let Some(log_file) = cli.log_file {
            config.log_file = Some(log_file);
        } else if config.log_file == None {
            // The log file wasn't specified. Default to process name
            config.log_file = Some(format!("logs/{}.log", process_name));
        }
        if let Some(ws_addr) = cli.ws_addr {
            config.ws_addr = Some(ws_addr);
        }
        if let Some(telnet_addr) = cli.telnet_addr {
            config.telnet_addr = Some(telnet_addr);
        }
        if let Some(mq_addr) = cli.mq_addr {
            config.mq_addr = Some(mq_addr);
        }
        config.debug = cli.debug;
        config.verbose = cli.verbose;
        Ok(config)
    }
pub fn new ( ) -> Result < Self , anyhow :: Error > { let cli = Config :: from_args ( ) ; // TODO: This is a very simplistic method that should be improved/strengthened let process_name = std :: env :: args ( ) . next ( ) . unwrap ( ) . split ( '/' ) . last ( ) . unwrap ( ) . to_string ( ) ; let mut input = String :: new ( ) ; File :: open ( & cli . config_file ) ? . read_to_string ( & mut input ) ? ; let mut config = toml :: from_str :: < Self > ( & input ) ? ; if let Some ( pid_file ) = cli . pid_file { config . pid_file = Some ( pid_file ) ; } else if config . pid_file == None { // The PID file wasn't specified. Default to process name config . pid_file = Some ( format ! ( " " process_name ) ) ; } if let Some ( log_file ) = cli . log_file { config . log_file = Some ( log_file ) ; } else if config . log_file == None { // The log file wasn't specified. Default to process name config . log_file = Some ( format ! ( " " process_name ) ) ; } if let Some ( ws_addr ) = cli . ws_addr { config . ws_addr = Some ( ws_addr ) ; } if let Some ( telnet_addr ) = cli . telnet_addr { config . telnet_addr = Some ( telnet_addr ) ; } if let Some ( mq_addr ) = cli . mq_addr { config . mq_addr = Some ( mq_addr ) ; } config . debug = cli . debug ; config . verbose = cli . verbose ; Ok ( config ) }
Returns a new Config
Read configuration from the file path specified in the Clap arguments struct.
Returns a new Config Read configuration from the file path specified in the Clap arguments struct .
errors
Returns `std::io::Error` if the config file can't be opened or read
Returns `toml::de::Error` if TOML parsing fails
Returns ` std :: io :: Error ` if the config file can ' t be opened or read Returns ` toml :: de :: Error ` if TOML parsing fails
panics
add possible panics here
add possible panics here