async fn resolve_config(args: &ArgMatches<'_>, ct: ConfigState) -> Result<(Config, Region)> {
    let regionguess = if let Some(r) = args.value_of("region") {
        r.into()
    } else {
        kubectl::current_context().await?
    };
    let (cfg, reg) = match Config::new(ct, &regionguess).await {
        Ok((c, r)) => (c, r),
        // Safety-path to ensure people aren't locked to older versions:
        Err(e) => {
            if let Some(v) = ConfigFallback::find_upgradeable_version()? {
                // Attempt an auto-upgrade if set
                if std::env::var("SHIPCAT_AUTOUPGRADE").is_ok() {
                    if cfg!(feature = "upgrade") {
                        warn!(
                            "shipcat.conf read in fallback mode - version < {} - upgrading",
                            v.to_string()
                        );
                        if let Err(e2) = shipcat::upgrade::self_upgrade(Some(v)).await {
                            return Err(Error::from(e).chain_err(|| e2));
                        }
                        std::process::exit(0);
                    } else {
                        error!("Cannot auto-upgrade if the self-upgrade feature is not compiled in");
                        return Err(e.into());
                    }
                } else {
                    // no auto-upgrade, just tell people what to do as usual.
                    let e2 = Config::bail_on_version_older_than(&v).unwrap_err();
                    return Err(Error::from(e).chain_err(|| Error::from(e2)));
                }
            }
            // still here? we are up to date, but have an invalid config.
            return Err(e.into());
        }
    };
    // Here? Config valid. Run usual safety checks.
    if let Err(e) = cfg.verify_version_pin(&reg.environment) {
        if args.is_present("strict-version-check") {
            return Err(e.into());
        } else if std::env::var("SHIPCAT_AUTOUPGRADE").is_ok() {
            let pin = cfg.get_appropriate_version_pin(&reg.environment).ok();
            warn!("shipcat out of date - autoupgrading"); // potentially to latest
            shipcat::upgrade::self_upgrade(pin).await?;
            // we could potentially shell out to new shipcat with args here
            // but the args were just consumed by clap, so..
            info!("Please retry your command");
            std::process::exit(0);
        } else {
            warn!("shipcat version less than pinned minimum - results may vary");
            warn!("{}", e);
            // Continue anyway ╚═[ ˵✖‿✖˵ ]═╝
        }
    }
    Ok((cfg, reg))
}
/// Create a config for a region
///
/// Resolves an optional "region" Arg or falls back to kube context.
/// This is the ONLY user of kubectl::current_context for sanity.
/// If the CLI entrypoint does not need a region-wide config, do not use this.
Create a config for a region
Resolves an optional "region" Arg or falls back to kube context.
This is the ONLY user of kubectl::current_context for sanity.
If the CLI entrypoint does not need a region-wide config, do not use this.
Create a config for a region Resolves an optional " region " Arg or falls back to kube context . This is the ONLY user of kubectl :: current_context for sanity . If the CLI entrypoint does not need a region - wide config do not use this .
async fn resolve_config(args: &ArgMatches<'_>, ct: ConfigState) -> Result<(Config, Region)> {
    let regionguess = if let Some(r) = args.value_of("region") {
        r.into()
    } else {
        kubectl::current_context().await?
    };
    let (cfg, reg) = match Config::new(ct, &regionguess).await {
        Ok((c, r)) => (c, r),
        // Safety-path to ensure people aren't locked to older versions:
        Err(e) => {
            if let Some(v) = ConfigFallback::find_upgradeable_version()? {
                // Attempt an auto-upgrade if set
                if std::env::var("SHIPCAT_AUTOUPGRADE").is_ok() {
                    if cfg!(feature = "upgrade") {
                        warn!(
                            "shipcat.conf read in fallback mode - version < {} - upgrading",
                            v.to_string()
                        );
                        if let Err(e2) = shipcat::upgrade::self_upgrade(Some(v)).await {
                            return Err(Error::from(e).chain_err(|| e2));
                        }
                        std::process::exit(0);
                    } else {
                        error!("Cannot auto-upgrade if the self-upgrade feature is not compiled in");
                        return Err(e.into());
                    }
                } else {
                    // no auto-upgrade, just tell people what to do as usual.
                    let e2 = Config::bail_on_version_older_than(&v).unwrap_err();
                    return Err(Error::from(e).chain_err(|| Error::from(e2)));
                }
            }
            // still here? we are up to date, but have an invalid config.
            return Err(e.into());
        }
    };
    // Here? Config valid. Run usual safety checks.
    if let Err(e) = cfg.verify_version_pin(&reg.environment) {
        if args.is_present("strict-version-check") {
            return Err(e.into());
        } else if std::env::var("SHIPCAT_AUTOUPGRADE").is_ok() {
            let pin = cfg.get_appropriate_version_pin(&reg.environment).ok();
            warn!("shipcat out of date - autoupgrading"); // potentially to latest
            shipcat::upgrade::self_upgrade(pin).await?;
            // we could potentially shell out to new shipcat with args here
            // but the args were just consumed by clap, so..
            info!("Please retry your command");
            std::process::exit(0);
        } else {
            warn!("shipcat version less than pinned minimum - results may vary");
            warn!("{}", e);
            // Continue anyway ╚═[ ˵✖‿✖˵ ]═╝
        }
    }
    Ok((cfg, reg))
}
async fn resolve_config ( args : & ArgMatches < ' _ > , ct : ConfigState ) -> Result < ( Config , Region ) > { let regionguess = if let Some ( r ) = args . value_of ( " " ) { r . into ( ) } else { kubectl :: current_context ( ) . await ? } ; let ( cfg , reg ) = match Config :: new ( ct , & regionguess ) . await { Ok ( ( c , r ) ) => ( c , r ) , // Safety-path to ensure people aren't locked to older versions: Err ( e ) => { if let Some ( v ) = ConfigFallback :: find_upgradeable_version ( ) ? { // Attempt an auto-upgrade if set if std :: env :: var ( " " ) . is_ok ( ) { if cfg ! ( feature " " ) { warn ! ( " " v to_string ( ) ) ; if let Err ( e2 ) = shipcat :: upgrade :: self_upgrade ( Some ( v ) ) . await { return Err ( Error :: from ( e ) . chain_err ( | | e2 ) ) ; } std :: process :: exit ( 0 ) ; } else { error ! ( " " ) ; return Err ( e . into ( ) ) ; } } else { // no auto-upgrade, just tell people what to do as usual. let e2 = Config :: bail_on_version_older_than ( & v ) . unwrap_err ( ) ; return Err ( Error :: from ( e ) . chain_err ( | | Error :: from ( e2 ) ) ) ; } } // still here? we are up to date, but have an invalid config. return Err ( e . into ( ) ) ; } } ; // Here? Config valid. Run usual safety checks. if let Err ( e ) = cfg . verify_version_pin ( & reg . environment ) { if args . is_present ( " " ) { return Err ( e . into ( ) ) ; } else if std :: env :: var ( " " ) . is_ok ( ) { let pin = cfg . get_appropriate_version_pin ( & reg . environment ) . ok ( ) ; warn ! ( " " ) ; // potentially to latest shipcat :: upgrade :: self_upgrade ( pin ) . await ? ; // we could potentially shell out to new shipcat with args here // but the args were just consumed by clap, so.. info ! ( " " ) ; std :: process :: exit ( 0 ) ; } else { warn ! ( " " ) ; warn ! ( " " e ) ; // Continue anyway ╚═[ ˵✖‿✖˵ ]═╝ } } Ok ( ( cfg , reg ) ) }
Create a config for a region
Resolves an optional "region" Arg or falls back to kube context.
Create a config for a region Resolves an optional " region " Arg or falls back to kube context .
args
&ArgMatches<'_>
ct
ConfigState
args
&ArgMatches<'_>
ct
ConfigState