pub struct Parameter<'a, T>(/* private fields */);Expand description
An argument/option for the command parser.
Used with CommandLineParser::add and SubCommand::add.
Implementations§
Source§impl<'a, T> Parameter<'a, T>
impl<'a, T> Parameter<'a, T>
Sourcepub fn option(
field: impl GenericCapturable<'a, T> + CliOption + 'a,
name: impl Into<String>,
short: Option<char>,
) -> Self
pub fn option( field: impl GenericCapturable<'a, T> + CliOption + 'a, name: impl Into<String>, short: Option<char>, ) -> Self
Create an option parameter.
§Example
use blarg::{Parameter, Switch};
let mut verbose: bool = false;
Parameter::option(Switch::new(&mut verbose, true), "verbose", Some('v'));Sourcepub fn argument(
field: impl GenericCapturable<'a, T> + CliArgument + 'a,
name: impl Into<String>,
) -> Self
pub fn argument( field: impl GenericCapturable<'a, T> + CliArgument + 'a, name: impl Into<String>, ) -> Self
Create an argument parameter.
§Example
use blarg::{Parameter, Scalar};
let mut verbose: bool = false;
Parameter::argument(Scalar::new(&mut verbose), "verbose");Sourcepub fn help(self, description: impl Into<String>) -> Self
pub fn help(self, description: impl Into<String>) -> Self
Document the help message for this parameter. If repeated, only the final message will apply to the parameter.
A help message describes the parameter in full sentence/paragraph format.
We recommend allowing blarg to format this field (ex: it is not recommended to use line breaks '\n').
See also:
§Example
use blarg::{Parameter, Scalar};
let mut verbose: bool = false;
Parameter::argument(Scalar::new(&mut verbose), "verbose")
.help("--this will get discarded--")
.help("Make the program output verbose. Description may include multiple sentences.");Sourcepub fn meta(self, descriptions: Vec<impl Into<String>>) -> Self
pub fn meta(self, descriptions: Vec<impl Into<String>>) -> Self
Document the meta message(s) for this parameter. If repeated, only the final message will apply to the parameter.
Meta message(s) describe short format extra details about the parameter. We recommend non-sentence information for this field.
See also:
§Example
use blarg::{Parameter, Scalar};
let mut verbose: bool = false;
Parameter::argument(Scalar::new(&mut verbose), "verbose")
.meta(vec!["--this will be discarded--"])
.meta(vec!["final extra", "details"]);Trait Implementations§
Source§impl<'a, T: Display> Choices<T> for Parameter<'a, T>
impl<'a, T: Display> Choices<T> for Parameter<'a, T>
Source§fn choice(self, variant: T, description: impl Into<String>) -> Self
fn choice(self, variant: T, description: impl Into<String>) -> Self
Document a choice’s help message for this parameter.
If repeated for the same variant of T, only the final message will apply to the parameter.
Repeat using different variants to document multiple choices.
Needn’t be exhaustive.
A choice help message describes the variant in full sentence/paragraph format.
We recommend allowing blarg to format this field (ex: it is not recommended to use line breaks '\n').
Notice, the documented or un-documented choices do not affect the actual command parser semantics. To actually limit the command parser semantics, be sure to use an enum.
See also:
§Example
use blarg::{prelude::*, Parameter, Scalar};
use std::str::FromStr;
let mut door: u32 = 0;
Parameter::argument(Scalar::new(&mut door), "door")
.choice(1, "--this will get discarded--")
.choice(1, "Enter door #1.")
.choice(2, "Enter door #2. Description may include multiple sentences.");