fn from_kernel_args(s: &str) -> Result<Self> {
        let known_args: BTreeSet<&'static str> =
            Self::Args::iter().map(|v| v.flag_name()).collect();

        let mut iter = shlex::Shlex::new(s);
        let mut args = Vec::new();
        for token in &mut iter {
            let (key, value) = match token.split_once('=') {
                Some((key, val)) => (key, Some(val)),
                None => (token.as_str(), None),
            };
            let key = key.replace('-', "_");
            let key = if known_args.contains(&format!("--{}", key).as_ref()) {
                format!("--{}", key)
            } else {
                key
            };

            args.push(match value {
                Some(value) => format!("{}={}", key, value),
                None => key,
            });
        }

        if iter.had_error {
            Err(anyhow!(
                "{} is invalid, successfully parsed {:?} so far",
                s,
                args,
            ))
        } else {
            Self::from_iter_safe(args).context("Failed to parse args")
        }
    }
/// Parse /proc/cmdline to get values from the booted kernel cmdline. Some
/// selected options are available when they have significance for MetalOS
/// code, for example 'metalos.os_uri'.
Parse /proc/cmdline to get values from the booted kernel cmdline. Some
selected options are available when they have significance for MetalOS
code, for example 'metalos.os_uri'.
Parse / proc / cmdline to get values from the booted kernel cmdline . Some selected options are available when they have significance for MetalOS code for example ' metalos . os_uri ' .
fn from_kernel_args(s: &str) -> Result<Self> {
        let known_args: BTreeSet<&'static str> =
            Self::Args::iter().map(|v| v.flag_name()).collect();
        let mut iter = shlex::Shlex::new(s);
        let mut args = Vec::new();
        for token in &mut iter {
            let (key, value) = match token.split_once('=') {
                Some((key, val)) => (key, Some(val)),
                None => (token.as_str(), None),
            };
            let key = key.replace('-', "_");
            let key = if known_args.contains(&format!("--{}", key).as_ref()) {
                format!("--{}", key)
            } else {
                key
            };
            args.push(match value {
                Some(value) => format!("{}={}", key, value),
                None => key,
            });
        }
        if iter.had_error {
            Err(anyhow!(
                "{} is invalid, successfully parsed {:?} so far",
                s,
                args,
            ))
        } else {
            Self::from_iter_safe(args).context("Failed to parse args")
        }
    }
fn from_kernel_args ( s : & str ) -> Result < Self > { let known_args : BTreeSet < & ' static str > = Self :: Args :: iter ( ) . map ( | v | v . flag_name ( ) ) . collect ( ) ; let mut iter = shlex :: Shlex :: new ( s ) ; let mut args = Vec :: new ( ) ; for token in & mut iter { let ( key , value ) = match token . split_once ( '=' ) { Some ( ( key , val ) ) => ( key , Some ( val ) ) , None => ( token . as_str ( ) , None ) , } ; let key = key . replace ( '-' , " " ) ; let key = if known_args . contains ( & format ! ( " " key ) . as_ref ( ) ) { format ! ( " " key ) } else { key } ; args . push ( match value { Some ( value ) => format ! ( " " key value ) , None => key , } ) ; } if iter . had_error { Err ( anyhow ! ( " " s args ) ) } else { Self :: from_iter_safe ( args ) . context ( " " ) } }
Parse /proc/cmdline to get values from the booted kernel cmdline.
Parse / proc / cmdline to get values from the booted kernel cmdline .
s
&str
s
&str