Skip to main content

Flag

Struct Flag 

Source
pub struct Flag {
Show 17 fields pub short: Option<char>, pub long: Option<String>, pub value_name: Option<String>, pub value_kind: ValueKind, pub choices: Vec<Text>, pub repeatable: bool, pub required: bool, pub negatable: bool, pub single_dash: bool, pub hidden: bool, pub deprecated: Option<Text>, pub inherited: bool, pub group: Option<String>, pub description: Option<Text>, pub default: Option<Text>, pub env_var: Option<String>, pub provenance: Provenance,
}
Expand description

A single flag/option, e.g. -i, --interactive.

Fields§

§short: Option<char>

Short spelling, e.g. Some('i') for -i.

§long: Option<String>

Long spelling, e.g. Some("interactive".into()) for --interactive.

§value_name: Option<String>

The value placeholder, e.g. "FILE" in --output FILE.

§value_kind: ValueKind

Whether this flag takes no value, a required value, or an optional one.

§choices: Vec<Text>

Enumerated choices, e.g. {json|yaml|table} for --format.

§repeatable: bool

True if this flag may be given more than once.

§required: bool

True if this flag is required.

§negatable: bool

True if the tool documents this boolean flag’s negation inline — GNU getopt_long’s --[no-]foo convention (git’s own --help formatter renders every negatable boolean this way). long always holds the base name ("foo", never "[no-]foo" or "no-foo"): this field is what lets the negatability survive the parse without smuggling [/] into the spelling users search and copy. See mandible-extract/src/help_text/grammar.rs’s try_long for where this is recognized, structurally, from the bracketed-prefix shape — never from a tool name.

§single_dash: bool

True when Self::long is spelled with one dash rather than two — the single-dash long-option convention (qemu -help, find -name, gcc -fdump-scos, bpftrace -vv), which is a real and common shape that this model previously had no way to say.

long holds the bare name either way ("help", "vv"), so every identity, merge and search path keeps working unchanged; this field only decides how many dashes Self::spelling puts in front of it. Storing "-help" in long instead would have put a dash inside the spelling users search and copy, exactly the mistake Self::negatable’s own doc comment records for --[no-]foo.

Recognized structurally and never from a tool name: see help_text::sections::repair_repeated_character_flags for the one shape that currently sets it.

§hidden: bool

True if this flag should be hidden by default.

§deprecated: Option<Text>

Some(reason) when this flag is deprecated.

§inherited: bool

True when this flag was declared on an ancestor node and propagated down (cobra “persistent flag” / carapace persistentflags). Rendered in a separate, dimmed group in the detail pane.

§group: Option<String>

Display grouping from the source, e.g. tar’s "Main operation mode".

§description: Option<Text>

The flag’s description.

§default: Option<Text>

The flag’s default value, if documented.

§env_var: Option<String>

An environment variable that also sets this flag, if documented.

§provenance: Provenance

Which source(s) contributed this flag’s fields.

Implementations§

Source§

impl Flag

Source

pub fn long(name: impl Into<String>, provenance: Provenance) -> Flag

A minimal flag with only a long spelling.

Source

pub fn key(&self) -> Option<FlagKey>

The canonical identity key used for cross-source matching and addressing: prefer the long name, fall back to the short letter. Returns None for a degenerate flag with neither (which cannot be addressed and is only matched positionally during merge).

Source

pub fn matches_key(&self, key: &FlagKey) -> bool

True if key addresses this flag, checking both spellings regardless of which one is considered canonical.

Source

pub fn spelling(&self) -> String

A human-readable spelling for display and clipboard copy, e.g. "-i, --interactive", "--output FILE", or "-S, --[no-]staged" for a negatable boolean — the [no-] is reconstructed for display from negatable, never stored in long itself (see the field’s doc comment).

A Self::single_dash flag renders with one dash (-help, -vv), reconstructed the same way and for the same reason: what a user has to type is a display concern, and putting it in long would corrupt the name every other code path matches on.

Trait Implementations§

Source§

impl Clone for Flag

Source§

fn clone(&self) -> Flag

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Flag

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Flag

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&Flag> for FlagSnapshot

Source§

fn from(f: &Flag) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Flag

Source§

fn eq(&self, other: &Flag) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Flag

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Flag

Auto Trait Implementations§

§

impl Freeze for Flag

§

impl RefUnwindSafe for Flag

§

impl Send for Flag

§

impl Sync for Flag

§

impl Unpin for Flag

§

impl UnsafeUnpin for Flag

§

impl UnwindSafe for Flag

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.