Skip to main content

get_argument

Function get_argument 

Source
pub fn get_argument(
    matches: &ArgMatches,
    name: &str,
) -> Result<String, ProcessError>
Expand description

Retrieves the value of a specified command-line argument.

§Arguments

  • matches - Clap argument matches object containing parsed arguments.
  • name - The name of the argument to retrieve.

§Returns

  • Result<String, ProcessError> - Returns the argument value on success or an error if the argument is missing.

§Errors

  • Returns ProcessError::MissingArgument if the specified argument is not provided.

§Examples

use clap::{Arg, Command};
use ssg::process::get_argument;

let matches = Command::new("t")
    .arg(Arg::new("name").long("name"))
    .get_matches_from(vec!["t", "--name", "value"]);
assert_eq!(get_argument(&matches, "name").unwrap(), "value");