Parameter

Struct Parameter 

Source
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>

Source

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'));
Source

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");
Source

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.");
Source

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>

Source§

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.");

Auto Trait Implementations§

§

impl<'a, T> Freeze for Parameter<'a, T>

§

impl<'a, T> !RefUnwindSafe for Parameter<'a, T>

§

impl<'a, T> !Send for Parameter<'a, T>

§

impl<'a, T> !Sync for Parameter<'a, T>

§

impl<'a, T> Unpin for Parameter<'a, T>

§

impl<'a, T> !UnwindSafe for Parameter<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.