diff options
Diffstat (limited to 'mingling/src')
| -rw-r--r-- | mingling/src/lib.rs | 15 | ||||
| -rw-r--r-- | mingling/src/parser/args.rs | 1 | ||||
| -rw-r--r-- | mingling/src/parser/picker.rs | 22 |
3 files changed, 36 insertions, 2 deletions
diff --git a/mingling/src/lib.rs b/mingling/src/lib.rs index 741effb..2b40989 100644 --- a/mingling/src/lib.rs +++ b/mingling/src/lib.rs @@ -43,29 +43,40 @@ //! // Output: //! -//! ``` +//! ```text //! > mycmd hello //! Hello, World! //! > mycmd hallo //! Dispatcher not found for command `hallo` //! ``` -// Re-Export Core lib +// Re-export Core lib pub use mingling::*; pub use mingling_core as mingling; +/// `Mingling` argument parser #[cfg(feature = "parser")] pub mod parser; +/// Re-export from `mingling_macros` #[allow(unused_imports)] pub mod macros { + /// Used to generate a struct implementing the `Chain` trait via a method pub use mingling_macros::chain; + /// Used to create a dispatcher that routes to a `Chain` pub use mingling_macros::dispatcher; + /// Used to create a dispatcher that routes to a `Renderer` pub use mingling_macros::dispatcher_render; + /// Used to collect data and create a command-line context pub use mingling_macros::gen_program; + /// Used to create a `Node` struct via a literal pub use mingling_macros::node; + /// Used to create a wrapper type for use with `Chain` and `Renderer` pub use mingling_macros::pack; + /// Used to print content within a `Renderer` context pub use mingling_macros::r_print; + /// Used to print content with a newline within a `Renderer` context pub use mingling_macros::r_println; + /// Used to generate a struct implementing the `Renderer` trait via a method pub use mingling_macros::renderer; } diff --git a/mingling/src/parser/args.rs b/mingling/src/parser/args.rs index a1f1eb0..0210b56 100644 --- a/mingling/src/parser/args.rs +++ b/mingling/src/parser/args.rs @@ -2,6 +2,7 @@ use std::mem::replace; use mingling_core::{Flag, special_argument, special_flag}; +/// User input arguments #[derive(Debug, Default)] pub struct Argument { vec: Vec<String>, diff --git a/mingling/src/parser/picker.rs b/mingling/src/parser/picker.rs index 9fcb3e6..7a0f211 100644 --- a/mingling/src/parser/picker.rs +++ b/mingling/src/parser/picker.rs @@ -1,17 +1,28 @@ use crate::parser::Argument; use mingling_core::Flag; +#[doc(hidden)] pub mod builtin; +/// A builder for extracting values from command-line arguments. +/// +/// The `Picker` struct holds parsed arguments and provides a fluent interface +/// to extract values associated with specific flags. pub struct Picker { + /// The parsed command-line arguments. pub args: Argument, } impl Picker { + /// Creates a new `Picker` from a value that can be converted into `Argument`. pub fn new(args: impl Into<Argument>) -> Picker { Picker { args: args.into() } } + /// Extracts a value for the given flag and returns a `Pick1` builder. + /// + /// The extracted type `TNext` must implement `Pickable` and `Default`. + /// If the flag is not present, the default value for `TNext` is used. pub fn pick<TNext>(mut self, val: impl Into<Flag>) -> Pick1<TNext> where TNext: Pickable<Output = TNext> + Default, @@ -30,8 +41,17 @@ impl<T: Into<Argument>> From<T> for Picker { } } +/// Extracts values from command-line arguments +/// +/// The `Pickable` trait defines how to extract the value of a specific flag from parsed arguments pub trait Pickable { + /// The output type produced by the extraction operation, must implement the `Default` trait type Output: Default; + + /// Extracts the value associated with the given flag from the provided arguments + /// + /// If the flag exists and the value can be successfully extracted, returns `Some(Output)`; + /// otherwise returns `None` fn pick(args: &mut Argument, flag: Flag) -> Option<Self::Output>; } @@ -61,6 +81,7 @@ macro_rules! define_pick_structs { where $($T: Pickable,)+ { + /// Unpacks into the corresponding tuple pub fn unpack(self) -> ($($T,)+) { ($(self.$val,)+) } @@ -75,6 +96,7 @@ macro_rules! impl_pick_structs { where $($T: Pickable,)+ { + /// Extracts a value for the given flag and returns a `PickN` builder. pub fn pick<TNext>(mut self, val: impl Into<mingling_core::Flag>) -> $next<$($T,)+ TNext> where TNext: Pickable<Output = TNext> + Default, |
