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=PATHselects 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=VALUEsets one value above every file. Repeatable; a later one wins,--set +discovery.peers=…appends. -
--check-configasks 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
impl CommandLine
Sourcepub fn extract<I>(args: I) -> Result<(Self, Vec<String>), ConfigError>where
I: IntoIterator<Item = String>,
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.
Sourcepub fn push_set(&mut self, assignment: &str) -> Result<(), ConfigError>
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.
Sourcepub fn push_entry(
&mut self,
path: &str,
fields: &[(&str, &str)],
flag: &str,
) -> Result<(), ConfigError>
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.
Sourcepub fn with_config(self, path: impl Into<PathBuf>) -> Self
pub fn with_config(self, path: impl Into<PathBuf>) -> Self
Selects a base file, as --config would.
Sourcepub fn config_path(&self) -> Option<&Path>
pub fn config_path(&self) -> Option<&Path>
The base file --config named.
Sourcepub fn sets(&self) -> &[(String, String)]
pub fn sets(&self) -> &[(String, String)]
Every --set, as (path, value), in the order given. The path keeps
a leading + on its last segment.
Sourcepub fn layer(&self) -> Result<Vec<Node>, ConfigError>
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.
Sourcepub fn apply(&self, config: &mut Config) -> Result<(), ConfigError>
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.