Skip to main content

CommandLine

Struct CommandLine 

Source
pub struct CommandLine { /* private fields */ }
Expand description

What the configuration flags on a command line said.

Every ZeroDDS program reads the same two flags, so they are parsed once here and the program sees only the arguments that are its own:

  • --config PATH / --config=PATH selects the base file. Given twice, it is refused: which of the two was meant is not the parser’s to decide.

  • --set PATH=VALUE / --set=PATH=VALUE sets one value above every file. Repeatable; a later one wins, --set +discovery.peers=… appends.

  • --check-config asks the program to validate and report the effective configuration and exit, without starting.

Parsing stops at --; what follows it belongs to the program.

Implementations§

Source§

impl CommandLine

Source

pub fn extract<I>(args: I) -> Result<(Self, Vec<String>), ConfigError>
where I: IntoIterator<Item = String>,

Takes the configuration flags out of args and returns the rest in their original order.

A long option in the rest written --opt=value comes back as --opt and value, so every program accepts both spellings the man pages use (before, amqp-, grpc- and corba-bridged and zerodds-ros2-shim answered --domain=3 with “unknown argument”, measured). What follows a -- is passed on untouched.

args excludes the program name.

§Errors

ConfigError::Usage for a flag without its value, a --set without =, an empty path, or --config given twice.

Source

pub fn push_set(&mut self, assignment: &str) -> Result<(), ConfigError>

Adds one PATH=VALUE, as a --set after the ones already given.

§Errors

ConfigError::Usage without = or with an invalid path.

Source

pub fn push_entry( &mut self, path: &str, fields: &[(&str, &str)], flag: &str, ) -> Result<(), ConfigError>

Appends one map of scalars to the list at path, for a program flag whose value is a list entry with several settings — a --set value is always one scalar. path is spelled as for --set (+types), flag is the flag as the operator wrote it and becomes the origin of every field. Entries are merged after every --set, in the order pushed.

§Errors

ConfigError::Usage for an invalid path, a path not written +name, or a field name that is not one path segment.

Source

pub fn check(&self) -> bool

Whether --check-config was given.

Source

pub fn with_config(self, path: impl Into<PathBuf>) -> Self

Selects a base file, as --config would.

Source

pub fn config_path(&self) -> Option<&Path>

The base file --config named.

Source

pub fn sets(&self) -> &[(String, String)]

Every --set, as (path, value), in the order given. The path keeps a leading + on its last segment.

Source

pub fn layer(&self) -> Result<Vec<Node>, ConfigError>

The --set values, one tree each, in the order given, each value’s origin naming its flag. Kept apart so that +name appends to the layers below instead of to an empty tree.

§Errors

ConfigError::Usage for an invalid path.

Source

pub fn apply(&self, config: &mut Config) -> Result<(), ConfigError>

Merges Self::layer onto config as its topmost source. Nothing is pushed when no --set was given, so Config::sources stays the list of what actually contributed.

§Errors

Whatever Config::push_each reports.

Trait Implementations§

Source§

impl Clone for CommandLine

Source§

fn clone(&self) -> Self

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 CommandLine

Source§

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

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

impl Default for CommandLine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for CommandLine

Source§

impl PartialEq for CommandLine

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CommandLine

Auto Trait Implementations§

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.