Skip to main content

ConfigBuilder

Struct ConfigBuilder 

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

Builder for functional-style configuration.

Provides a chainable API for defining configuration options, similar to the JavaScript makeConfig API.

§Example

use lino_arguments::make_config;

let config = make_config(|c| {
    c.lenv(".lenv")
     .option("port", "Server port", "3000")
     .option_short("api-key", 'k', "API key", "")
     .flag("verbose", "Enable verbose logging")
});

Implementations§

Source§

impl ConfigBuilder

Source

pub fn name(&mut self, name: &str) -> &mut Self

Set the application name for help text.

Source

pub fn about(&mut self, about: &str) -> &mut Self

Set the application description for help text.

Source

pub fn version(&mut self, version: &str) -> &mut Self

Set the application version for –version flag.

Source

pub fn lenv(&mut self, path: &str) -> &mut Self

Load a .lenv configuration file (without overriding existing env vars).

Source

pub fn lenv_override(&mut self, path: &str) -> &mut Self

Load a .lenv configuration file, overriding existing env vars.

Source

pub fn env(&mut self, path: &str) -> &mut Self

Load a .env configuration file (without overriding existing env vars).

Source

pub fn env_override(&mut self, path: &str) -> &mut Self

Load a .env configuration file, overriding existing env vars.

Source

pub fn option( &mut self, name: &str, description: &str, default: &str, ) -> &mut Self

Define a string/number option with a long name, description, and default value.

Source

pub fn option_short( &mut self, name: &str, short: char, description: &str, default: &str, ) -> &mut Self

Define a string/number option with both short and long names.

Source

pub fn flag(&mut self, name: &str, description: &str) -> &mut Self

Define a boolean flag (defaults to false).

Source

pub fn flag_short( &mut self, name: &str, short: char, description: &str, ) -> &mut Self

Define a boolean flag with a short name.

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> 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, 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.