fn parse_get_args()

in sources/api/apiclient/src/main.rs [369:406]


fn parse_get_args(args: Vec<String>) -> Subcommand {
    let mut prefixes = vec![];
    let mut uri = None;

    let mut iter = args.into_iter();
    while let Some(arg) = iter.next() {
        match &arg {
            x if x.starts_with('-') => usage_msg(&format!("Unknown argument '{}'", x)),

            x if x.starts_with('/') => {
                if let Some(_existing_val) = uri.replace(arg) {
                    usage_msg("You can only specify one URI.");
                }
            }

            // All other arguments are settings prefixes to fetch.
            _ => prefixes.push(arg),
        }
    }

    if let Some(uri) = uri {
        if !prefixes.is_empty() {
            usage_msg("You can specify prefixes or a URI, but not both.");
        }
        Subcommand::Get(GetArgs::Uri(uri))
    } else if !prefixes.is_empty() {
        if uri.is_some() {
            usage_msg("You can specify prefixes or a URI, but not both.");
        }
        Subcommand::Get(GetArgs::Prefixes(prefixes))
    } else {
        // A reasonable default is showing OS info and settings.
        Subcommand::Get(GetArgs::Prefixes(vec![
            "os.".to_string(),
            "settings.".to_string(),
        ]))
    }
}