Crate argser

Source
Expand description

§Argser

A library to handle configuration for Programs

§Examples

§Simple Use-Case

  • name: The Name
§Code
use argser::argser;

#[argser]
struct Options {
    name: String,
}

fn main() {
    let opts: Options = argser::parse_cli().unwrap();

    println!("Hello {}", opts.name);
}

§Using Subcategories

  • name: The Name
  • con.domain: The Domain
  • con.port: The Port
§Code
use argser::argser;

#[argser]
struct Options {
	name: String,
	#[argser(subcategory)]
	con: Connection,
}

#[argser]
struct Connection {
	domain: String,
	port: u16,
}

fn main() {
  let opts: Options = argser::parse_cli().unwrap();

  println!("Hello {}", opts.name);
	println!("Connecting to {}:{}", opts.con.domain, opts.con.port);
}

Modules§

provider
This represents the Collection of Providers that collect Arguments from various sources.

Structs§

ArgumentDetail
Information regarding a single Argument

Enums§

ParseError
The Error returned when attempting to Parse the Arguments

Traits§

ArgProvider
Defines the interface that needs to be implemented by Argument-Providers, this enables users to source the arguments that should be used from different Parts, like CLI-Args, Environment-Variables, etc.
FromArgs
Defines the Interface to parse a Collection of provided Arguments into a single concrete Struct.
ParseFromArgs
Defines the interface to parse a List-Argument Values into single Conecrete Value for a Field in a CLI-Struct

Functions§

parse_args_from_providers
This will load all the Arguments from the given Providers and then attempt to parse an instance of T from that Collection of Arguments
parse_cli
This is a simple Wrapper for parse_args_from_providers that automatically uses the Cli ArgProvider to collect Arguments and then Parse them

Attribute Macros§

argser
This will automatically implement the argser::FromArgs trait for the Struct it is applied on, while considering all the Configuration on the Struct and all its parts when generating the implemenatation.