pub fn determine_update_mode(matches: &ArgMatches) -> UpdateMode
Expand description

Determine the “mode” for the update operation to perform, if any.

Parses the backup options and converts them to an instance of UpdateMode for further processing.

Takes [clap::ArgMatches] as argument which must contain the options from arguments::update() or arguments::update_no_args(). Otherwise the ReplaceAll mode is returned unconditionally.

Examples

Here’s how one would integrate the update mode determination into an application.

#[macro_use]
extern crate uucore;
use uucore::update_control::{self, UpdateMode};
use clap::{Command, Arg, ArgMatches};

fn main() {
    let matches = Command::new("command")
        .arg(update_control::arguments::update())
        .arg(update_control::arguments::update_no_args())
        .get_matches_from(vec![
            "command", "--update=all"
        ]);

    let update_mode = update_control::determine_update_mode(&matches);
    assert_eq!(update_mode, UpdateMode::ReplaceAll)
}