fn make_spu_id(cli_cfg: &SpuOpt, _file_cfg: &Option<SpuConfigFile>) -> Result<SpuId, IoError> {
        // 1) check cli
        let spu_id = cli_cfg.id;

        // 2) environment variable (optional field, ignore errors)
        if let Some(some_id) = spu_id {
            debug!("spu id is supplied by config: {}",some_id);
            Ok(some_id)
        } else {
            debug!("no spu is supplied, looking up env");
            if let Ok(id_str) = env::var(FLV_SPU_ID) {
                debug!("found spu id from env: {}",id_str);
                let id = id_str.parse().map_err(|err| {
                    IoError::new(ErrorKind::InvalidInput, format!("spu-id: {}", err))
                })?;
                Ok(id)
            } else {
                
                // try get special env SPU which has form of {}-{id} when in as in-cluster config
                if let Ok(spu_name) = env::var("SPU_INDEX") {
                    info!("extracting SPU from: {}",spu_name);
                    let spu_tokens: Vec<&str> = spu_name.split('-').collect();
                    if spu_tokens.len() < 2 {
                        error!("SPU is invalid format. bailing out");
                    } else {
                        let spu_token = spu_tokens[spu_tokens.len()-1];
                        let id: SpuId = match spu_token.parse() {
                            Ok(id) => id,
                            Err(err) => {
                                error!("invalid spu id: {}. terminating it",err);
                                std::process::exit(-1);
                            }
                        };
                        info!("found SPU INDEX ID: {}",id);

                        // now we get SPU_MIN which tells min
                        let spu_min_var = env::var("SPU_MIN").unwrap_or("0".to_owned());
                        debug!("found SPU MIN ID: {}",spu_min_var);
                        let base_id: SpuId = spu_min_var.parse().expect("spu min should be integer");
                        return Ok(id + base_id)
                    }
                } else {
                    error!("no spu founded from env. this is bad");
                }

                for (key, value) in env::vars() {
                    debug!("{}: {}", key, value);
                }   
                std::process::exit(0x0100);
            }
        }
    
    }
/// Generate spu-id by combining all config elements. Returns error on failure.
Generate spu-id by combining all config elements. Returns error on failure.
Generate spu - id by combining all config elements . Returns error on failure .
fn make_spu_id(cli_cfg: &SpuOpt, _file_cfg: &Option<SpuConfigFile>) -> Result<SpuId, IoError> {
        // 1) check cli
        let spu_id = cli_cfg.id;
        // 2) environment variable (optional field, ignore errors)
        if let Some(some_id) = spu_id {
            debug!("spu id is supplied by config: {}",some_id);
            Ok(some_id)
        } else {
            debug!("no spu is supplied, looking up env");
            if let Ok(id_str) = env::var(FLV_SPU_ID) {
                debug!("found spu id from env: {}",id_str);
                let id = id_str.parse().map_err(|err| {
                    IoError::new(ErrorKind::InvalidInput, format!("spu-id: {}", err))
                })?;
                Ok(id)
            } else {
                // try get special env SPU which has form of {}-{id} when in as in-cluster config
                if let Ok(spu_name) = env::var("SPU_INDEX") {
                    info!("extracting SPU from: {}",spu_name);
                    let spu_tokens: Vec<&str> = spu_name.split('-').collect();
                    if spu_tokens.len() < 2 {
                        error!("SPU is invalid format. bailing out");
                    } else {
                        let spu_token = spu_tokens[spu_tokens.len()-1];
                        let id: SpuId = match spu_token.parse() {
                            Ok(id) => id,
                            Err(err) => {
                                error!("invalid spu id: {}. terminating it",err);
                                std::process::exit(-1);
                            }
                        };
                        info!("found SPU INDEX ID: {}",id);
                        // now we get SPU_MIN which tells min
                        let spu_min_var = env::var("SPU_MIN").unwrap_or("0".to_owned());
                        debug!("found SPU MIN ID: {}",spu_min_var);
                        let base_id: SpuId = spu_min_var.parse().expect("spu min should be integer");
                        return Ok(id + base_id)
                    }
                } else {
                    error!("no spu founded from env. this is bad");
                }
                for (key, value) in env::vars() {
                    debug!("{}: {}", key, value);
                }   
                std::process::exit(0x0100);
            }
        }
    }
fn make_spu_id ( cli_cfg : & SpuOpt , _file_cfg : & Option < SpuConfigFile > ) -> Result < SpuId , IoError > { // 1) check cli let spu_id = cli_cfg . id ; // 2) environment variable (optional field, ignore errors) if let Some ( some_id ) = spu_id { debug ! ( " " some_id ) ; Ok ( some_id ) } else { debug ! ( " " ) ; if let Ok ( id_str ) = env :: var ( FLV_SPU_ID ) { debug ! ( " " id_str ) ; let id = id_str . parse ( ) . map_err ( | err | { IoError :: new ( ErrorKind :: InvalidInput , format ! ( " " err ) ) } ) ? ; Ok ( id ) } else { // try get special env SPU which has form of {}-{id} when in as in-cluster config if let Ok ( spu_name ) = env :: var ( " " ) { info ! ( " " spu_name ) ; let spu_tokens : Vec < & str > = spu_name . split ( '-' ) . collect ( ) ; if spu_tokens . len ( ) < 2 { error ! ( " " ) ; } else { let spu_token = spu_tokens [ spu_tokens . len ( ) - 1 ] ; let id : SpuId = match spu_token . parse ( ) { Ok ( id ) => id , Err ( err ) => { error ! ( " " err ) ; std :: process :: exit ( - 1 ) ; } } ; info ! ( " " id ) ; // now we get SPU_MIN which tells min let spu_min_var = env :: var ( " " ) . unwrap_or ( " " . to_owned ( ) ) ; debug ! ( " " spu_min_var ) ; let base_id : SpuId = spu_min_var . parse ( ) . expect ( " " ) ; return Ok ( id + base_id ) } } else { error ! ( " " ) ; } for ( key , value ) in env :: vars ( ) { debug ! ( " " key value ) ; } std :: process :: exit ( 0x0100 ) ; } } }
Generate spu-id by combining all config elements.
Generate spu - id by combining all config elements .
cli_cfg
&SpuOpt
_file_cfg
&Option<SpuConfigFile>
cli_cfg
&SpuOpt
_file_cfg
&Option<SpuConfigFile>