[−][src]Struct spirit_cfg_helpers::CfgHelp
A command line options fragment to add the --help-config
option.
For the user to be able to configure an application, the user needs to know what options can be configured. Usually, this is explained using an example configuration file or through a manually written documentation. However, maintaining either is a lot of work, not mentioning that various spirit crates provide configuration fragments composed from several type parameters so hunting down all the available options might be hard.
This helper uses the StructDoc
trait to extract the structure and documentation of the
configuration automatically. Usually, its derive will extract description from fields' doc
comments. See the structdoc crate's documentation to know how to let the documentation be
created semi-automatically. All the configuration fragments provided by the spirit crates
implement StructDoc
, unless their [cfg-help
] feature is disabled.
When the --help-config
is specified, this auto-generated documentation is printed and the
application exits.
The fragment can be used either manually with the help
method or by
registering the extension
within an
Extensible
.
Examples
use serde_derive::Deserialize; use spirit::Spirit; use spirit::prelude::*; use spirit_cfg_helpers::CfgHelp; use structdoc::StructDoc; use structopt::StructOpt; #[derive(Default, Deserialize, StructDoc)] struct Cfg { /// A very much useless but properly documented option. option: Option<String>, } #[derive(Debug, StructOpt)] struct Opts { #[structopt(flatten)] help: CfgHelp, } impl Opts { fn help(&self) -> &CfgHelp { &self.help } } fn main() { Spirit::<Opts, Cfg>::new() .with(CfgHelp::extension(Opts::help)) .run(|_| Ok(())); }
Implementations
impl CfgHelp
[src]
pub fn help<C: StructDoc>(&self)
[src]
Show the help and exit if it was specified as an option.
This can be called manually to check for the command line option at the right time. If
it was specified, the help for the C
type is printed and the application exits. If
the command line was not specified, this does nothing.
Note that the C
type is passed as type parameter, therefore this needs to be invoked
with the turbofish syntax.
The preferred way is usually by registering the extension
.
Examples
use serde_derive::Deserialize; use spirit_cfg_helpers::CfgHelp; use structdoc::StructDoc; use structopt::StructOpt; #[derive(Deserialize, StructDoc)] struct Cfg { /// A very much useless but properly documented option option: Option<String>, } #[derive(StructOpt)] struct Opts { #[structopt(flatten)] help: CfgHelp, } let opts = Opts::from_args(); opts.help.help::<Cfg>();
pub fn extension<O, C, F>(extract: F) -> impl Extension<Builder<O, C>> where
F: FnOnce(&O) -> &Self + Send + 'static,
O: Debug + StructOpt + Send + Sync + 'static,
C: DeserializeOwned + StructDoc + Send + Sync + 'static,
[src]
F: FnOnce(&O) -> &Self + Send + 'static,
O: Debug + StructOpt + Send + Sync + 'static,
C: DeserializeOwned + StructDoc + Send + Sync + 'static,
A helper to be registered within an Extensible
.
The extractor should take the whole command line options structure and provide
reference to just the CfgHelp
instance.
Trait Implementations
impl Clone for CfgHelp
[src]
impl Debug for CfgHelp
[src]
impl Default for CfgHelp
[src]
impl StructOpt for CfgHelp
[src]
fn clap<'a, 'b>() -> App<'a, 'b>
[src]
fn from_clap(matches: &ArgMatches<'_>) -> Self
[src]
fn from_args() -> Self
[src]
fn from_args_safe() -> Result<Self, Error>
[src]
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator,
<I as IntoIterator>::Item: Into<OsString>,
<I as IntoIterator>::Item: Clone,
[src]
I: IntoIterator,
<I as IntoIterator>::Item: Into<OsString>,
<I as IntoIterator>::Item: Clone,
fn from_iter_safe<I>(iter: I) -> Result<Self, Error> where
I: IntoIterator,
<I as IntoIterator>::Item: Into<OsString>,
<I as IntoIterator>::Item: Clone,
[src]
I: IntoIterator,
<I as IntoIterator>::Item: Into<OsString>,
<I as IntoIterator>::Item: Clone,
impl StructOptInternal for CfgHelp
[src]
fn augment_clap<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b>
[src]
fn is_subcommand() -> bool
[src]
fn from_subcommand(_sub: (&'b str, Option<&'b ArgMatches<'a>>)) -> Option<Self>
[src]
Auto Trait Implementations
impl RefUnwindSafe for CfgHelp
impl Send for CfgHelp
impl Sync for CfgHelp
impl Unpin for CfgHelp
impl UnwindSafe for CfgHelp
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoResult<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,