fn config_command(
    mut toml_config: Config,
    matches: &ArgMatches,
) -> Result<Config, Box<dyn StdError>> {
    // resolution
    if let Some(res) = matches.value_of("Resolution") {
        let reg_res = Regex::new(r"^([1-9]\d{1,4})x([1-9]\d{1,4})").unwrap();

        if reg_res.is_match(res) {
            for cap in reg_res.captures_iter(res) {
                let res_x = cap.at(1).unwrap().parse::<u32>().unwrap();
                let res_y = cap.at(2).unwrap().parse::<u32>().unwrap();
                toml_config.resolution = Dimension2::new(res_x, res_y);
            }
        } else {
            return Err("invalid resolution in command line argument".into());
        }
    }

    // Windows mode
    if let Some(mode) = matches.value_of("WindowMode") {
        match mode {
            "Windowed" => toml_config.window_mode = WindowMode::Windowed,
            "FullScreen" => toml_config.window_mode = WindowMode::FullScreen,
            _ => return Err("invalid Window Mode in command line argument".into()),
        }
    }

    // Tessellation
    if let Some(tessellation) = matches.value_of("Tessellation") {
        match tessellation {
            "on" => toml_config.tessellation = true,
            "off" => toml_config.tessellation = false,
            _ => return Err("Tessellation can only be set on or off on command line".into()),
        }
    }

    // Bloom
    if let Some(bloom) = matches.value_of("Bloom") {
        match bloom {
            "on" => toml_config.bloom = true,
            "off" => toml_config.bloom = false,
            _ => return Err("Bloom can only be set on or off on command line".into()),
        }
    }

    // Vsync
    if let Some(sync) = matches.value_of("Vsync") {
        match sync {
            "on" => toml_config.vsync = true,
            "off" => toml_config.vsync = false,
            _ => return Err("Vsync can only be set on or off on command line".into()),
        }
    }

    // Highlighting
    if let Some(highlight) = matches.value_of("HighlightPillar") {
        match highlight {
            "on" => toml_config.highlight_pillar = true,
            "off" => toml_config.highlight_pillar = false,
            _ => return Err("Highlighting from command line is invalid".into()),
        }
    }

    // world Seed
    if let Some(seed) = matches.value_of("Seed") {
        match seed.parse::<u64>() {
            Ok(n) => toml_config.seed = n,
            _ => return Err("Seed from command line is invalid".into()),
        }
    }

    Ok(toml_config)
}
/// read configuration from command line
/// overwrite config values with command line values
/// return updated config
read configuration from command line
overwrite config values with command line values
return updated config
read configuration from command line overwrite config values with command line values return updated config
fn config_command(
    mut toml_config: Config,
    matches: &ArgMatches,
) -> Result<Config, Box<dyn StdError>> {
    // resolution
    if let Some(res) = matches.value_of("Resolution") {
        let reg_res = Regex::new(r"^([1-9]\d{1,4})x([1-9]\d{1,4})").unwrap();
        if reg_res.is_match(res) {
            for cap in reg_res.captures_iter(res) {
                let res_x = cap.at(1).unwrap().parse::<u32>().unwrap();
                let res_y = cap.at(2).unwrap().parse::<u32>().unwrap();
                toml_config.resolution = Dimension2::new(res_x, res_y);
            }
        } else {
            return Err("invalid resolution in command line argument".into());
        }
    }
    // Windows mode
    if let Some(mode) = matches.value_of("WindowMode") {
        match mode {
            "Windowed" => toml_config.window_mode = WindowMode::Windowed,
            "FullScreen" => toml_config.window_mode = WindowMode::FullScreen,
            _ => return Err("invalid Window Mode in command line argument".into()),
        }
    }
    // Tessellation
    if let Some(tessellation) = matches.value_of("Tessellation") {
        match tessellation {
            "on" => toml_config.tessellation = true,
            "off" => toml_config.tessellation = false,
            _ => return Err("Tessellation can only be set on or off on command line".into()),
        }
    }
    // Bloom
    if let Some(bloom) = matches.value_of("Bloom") {
        match bloom {
            "on" => toml_config.bloom = true,
            "off" => toml_config.bloom = false,
            _ => return Err("Bloom can only be set on or off on command line".into()),
        }
    }
    // Vsync
    if let Some(sync) = matches.value_of("Vsync") {
        match sync {
            "on" => toml_config.vsync = true,
            "off" => toml_config.vsync = false,
            _ => return Err("Vsync can only be set on or off on command line".into()),
        }
    }
    // Highlighting
    if let Some(highlight) = matches.value_of("HighlightPillar") {
        match highlight {
            "on" => toml_config.highlight_pillar = true,
            "off" => toml_config.highlight_pillar = false,
            _ => return Err("Highlighting from command line is invalid".into()),
        }
    }
    // world Seed
    if let Some(seed) = matches.value_of("Seed") {
        match seed.parse::<u64>() {
            Ok(n) => toml_config.seed = n,
            _ => return Err("Seed from command line is invalid".into()),
        }
    }
    Ok(toml_config)
}
fn config_command ( mut toml_config : Config , matches : & ArgMatches , ) -> Result < Config , Box < dyn StdError > > { // resolution if let Some ( res ) = matches . value_of ( " " ) { let reg_res = Regex :: new ( r"^([1-9]\d{1,4})x([1-9]\d{1,4})" ) . unwrap ( ) ; if reg_res . is_match ( res ) { for cap in reg_res . captures_iter ( res ) { let res_x = cap . at ( 1 ) . unwrap ( ) . parse :: < u32 > ( ) . unwrap ( ) ; let res_y = cap . at ( 2 ) . unwrap ( ) . parse :: < u32 > ( ) . unwrap ( ) ; toml_config . resolution = Dimension2 :: new ( res_x , res_y ) ; } } else { return Err ( " " . into ( ) ) ; } } // Windows mode if let Some ( mode ) = matches . value_of ( " " ) { match mode { " " => toml_config . window_mode = WindowMode :: Windowed , " " => toml_config . window_mode = WindowMode :: FullScreen , _ => return Err ( " " . into ( ) ) , } } // Tessellation if let Some ( tessellation ) = matches . value_of ( " " ) { match tessellation { " " => toml_config . tessellation = true , " " => toml_config . tessellation = false , _ => return Err ( " " . into ( ) ) , } } // Bloom if let Some ( bloom ) = matches . value_of ( " " ) { match bloom { " " => toml_config . bloom = true , " " => toml_config . bloom = false , _ => return Err ( " " . into ( ) ) , } } // Vsync if let Some ( sync ) = matches . value_of ( " " ) { match sync { " " => toml_config . vsync = true , " " => toml_config . vsync = false , _ => return Err ( " " . into ( ) ) , } } // Highlighting if let Some ( highlight ) = matches . value_of ( " " ) { match highlight { " " => toml_config . highlight_pillar = true , " " => toml_config . highlight_pillar = false , _ => return Err ( " " . into ( ) ) , } } // world Seed if let Some ( seed ) = matches . value_of ( " " ) { match seed . parse :: < u64 > ( ) { Ok ( n ) => toml_config . seed = n , _ => return Err ( " " . into ( ) ) , } } Ok ( toml_config ) }
read configuration from command line
overwrite config values with command line values
return updated config
read configuration from command line overwrite config values with command line values return updated config
toml_config
Config
matches
&ArgMatches