pub(crate) fn init() -> Result<Self, Error> {
        // Use the user's home directory to store configuration files and profile data
        let config_file = data_path().join(CONFIG_FILENAME);

        // If a default file is not found, create one with default configuration
        if !Path::new(&config_file).exists() {
            create_file(&config_file, &DefaultConfig::default())?;
        };

        let mut buffer = String::new();
        let mut file = OpenOptions::new().read(true).open(&config_file)?;
        file.read_to_string(&mut buffer)?;
        let config: DefaultConfig = match toml::from_str(&buffer) {
            Ok(x) => x,
            Err(_err) => {
                let mut file = OpenOptions::new()
                    .create_new(false)
                    .read(true)
                    .truncate(true)
                    .write(true)
                    .append(false)
                    .open(config_file)?;

                let buffer = toml::to_vec(&DefaultConfig::default())?;
                file.write_all(&buffer)?;
                file.flush()?;

                DefaultConfig::default()
            }
        };

        Ok(config)
    }
/// Initialize the configuration by reading the default confgiruation file.
/// If no file is found, a new one will be created with default options.
Initialize the configuration by reading the default confgiruation file.
If no file is found, a new one will be created with default options.
Initialize the configuration by reading the default confgiruation file . If no file is found a new one will be created with default options .
pub(crate) fn init() -> Result<Self, Error> {
        // Use the user's home directory to store configuration files and profile data
        let config_file = data_path().join(CONFIG_FILENAME);
        // If a default file is not found, create one with default configuration
        if !Path::new(&config_file).exists() {
            create_file(&config_file, &DefaultConfig::default())?;
        };
        let mut buffer = String::new();
        let mut file = OpenOptions::new().read(true).open(&config_file)?;
        file.read_to_string(&mut buffer)?;
        let config: DefaultConfig = match toml::from_str(&buffer) {
            Ok(x) => x,
            Err(_err) => {
                let mut file = OpenOptions::new()
                    .create_new(false)
                    .read(true)
                    .truncate(true)
                    .write(true)
                    .append(false)
                    .open(config_file)?;
                let buffer = toml::to_vec(&DefaultConfig::default())?;
                file.write_all(&buffer)?;
                file.flush()?;
                DefaultConfig::default()
            }
        };
        Ok(config)
    }
pub ( crate ) fn init ( ) -> Result < Self , Error > { // Use the user's home directory to store configuration files and profile data let config_file = data_path ( ) . join ( CONFIG_FILENAME ) ; // If a default file is not found, create one with default configuration if ! Path :: new ( & config_file ) . exists ( ) { create_file ( & config_file , & DefaultConfig :: default ( ) ) ? ; } ; let mut buffer = String :: new ( ) ; let mut file = OpenOptions :: new ( ) . read ( true ) . open ( & config_file ) ? ; file . read_to_string ( & mut buffer ) ? ; let config : DefaultConfig = match toml :: from_str ( & buffer ) { Ok ( x ) => x , Err ( _err ) => { let mut file = OpenOptions :: new ( ) . create_new ( false ) . read ( true ) . truncate ( true ) . write ( true ) . append ( false ) . open ( config_file ) ? ; let buffer = toml :: to_vec ( & DefaultConfig :: default ( ) ) ? ; file . write_all ( & buffer ) ? ; file . flush ( ) ? ; DefaultConfig :: default ( ) } } ; Ok ( config ) }
Initialize the configuration by reading the default confgiruation file.
Initialize the configuration by reading the default confgiruation file .