/// Load config from `--config_file` arg (if present) and then override
/// with any values provided on the command line.
Load config from `--config_file` arg (if present) and then override
with any values provided on the command line.
Load config from ` -- config_file ` arg ( if present ) and then override with any values provided on the command line .
pub fn new() -> Result<Self, ConfigError> {
        let mut config = if CONFIG_FILE.is_present() {
            read_config_from_file(CONFIG_FILE.flag)?
        } else {
            Config::default()
        };
        if DISCOVER_EVERY.is_present() {
            config.discover_every = parse_duration(DISCOVER_EVERY.flag).map_err(|source| {
                ConfigError::InvalidDuration {
                    duration: DISCOVER_EVERY.flag.to_string(),
                    source,
                }
            })?;
        }
        if METRICS_ADDR.is_present() {
            config.metrics_addr = METRICS_ADDR.flag.parse()?;
        }
        config.log = ic_p8s_service_discovery_log::from_flags(config.log)?;
        config.nns = nns::from_flags(config.nns)?;
        if config.nns.urls.is_empty() {
            return Err(ConfigError::NnsUrlMissing);
        }
        if SERVICE_DISCOVERY_FILE.is_present() {
            config.service_discovery_file = SERVICE_DISCOVERY_FILE.flag.to_string();
        }
        if NNS_PUBLIC_KEY_PATH.is_present() {
            config.nns_public_key_path = NNS_PUBLIC_KEY_PATH.flag.to_string();
        }
        if config.service_discovery_file.is_empty() {
            return Err(ConfigError::MissingServiceDiscoveryFile);
        }
        if SERVICE_DISCOVERY_FILE_MODE.is_present() {
            config.service_discovery_file_mode = parse::<u32>(SERVICE_DISCOVERY_FILE_MODE.flag)
                .map_err(|source| ConfigError::InvalidPermissionsMode {
                    mode: SERVICE_DISCOVERY_FILE_MODE.flag.to_string(),
                    source,
                })?;
        }
        if IC_NAME.is_present() && !IC_NAME.flag.to_string().is_empty() {
            config.ic_name = IC_NAME.flag.to_string();
        }
        if config.ic_name.is_empty() {
            return Err(ConfigError::MissingIcName);
        }
        Ok(config)
    }
pub fn new ( ) -> Result < Self , ConfigError > { let mut config = if CONFIG_FILE . is_present ( ) { read_config_from_file ( CONFIG_FILE . flag ) ? } else { Config :: default ( ) } ; if DISCOVER_EVERY . is_present ( ) { config . discover_every = parse_duration ( DISCOVER_EVERY . flag ) . map_err ( | source | { ConfigError :: InvalidDuration { duration : DISCOVER_EVERY . flag . to_string ( ) , source , } } ) ? ; } if METRICS_ADDR . is_present ( ) { config . metrics_addr = METRICS_ADDR . flag . parse ( ) ? ; } config . log = ic_p8s_service_discovery_log :: from_flags ( config . log ) ? ; config . nns = nns :: from_flags ( config . nns ) ? ; if config . nns . urls . is_empty ( ) { return Err ( ConfigError :: NnsUrlMissing ) ; } if SERVICE_DISCOVERY_FILE . is_present ( ) { config . service_discovery_file = SERVICE_DISCOVERY_FILE . flag . to_string ( ) ; } if NNS_PUBLIC_KEY_PATH . is_present ( ) { config . nns_public_key_path = NNS_PUBLIC_KEY_PATH . flag . to_string ( ) ; } if config . service_discovery_file . is_empty ( ) { return Err ( ConfigError :: MissingServiceDiscoveryFile ) ; } if SERVICE_DISCOVERY_FILE_MODE . is_present ( ) { config . service_discovery_file_mode = parse :: < u32 > ( SERVICE_DISCOVERY_FILE_MODE . flag ) . map_err ( | source | ConfigError :: InvalidPermissionsMode { mode : SERVICE_DISCOVERY_FILE_MODE . flag . to_string ( ) , source , } ) ? ; } if IC_NAME . is_present ( ) && ! IC_NAME . flag . to_string ( ) . is_empty ( ) { config . ic_name = IC_NAME . flag . to_string ( ) ; } if config . ic_name . is_empty ( ) { return Err ( ConfigError :: MissingIcName ) ; } Ok ( config ) }
Load config from `--config_file` arg (if present) and then override
with any values provided on the command line.
Load config from ` -- config_file ` arg ( if present ) and then override with any values provided on the command line .