64 lines
1.8 KiB
Rust
64 lines
1.8 KiB
Rust
//! File: env/commandlinearguments.rs
|
|
//! Created On: Thu 26 Dec 2019 09:01:57 PM CET
|
|
//! Last Modfied: Thu 26 Dec 2019 09:01:57 PM CET
|
|
//! Author: Jali <jali@orca-central.de>
|
|
//! Description: Defines the command line arguments that were passed
|
|
|
|
use clap::ArgMatches;
|
|
use std::str::FromStr;
|
|
|
|
/**
|
|
* # Summary
|
|
* Stores the command line arguments from our
|
|
* service.
|
|
*/
|
|
pub struct CommandLineArguments {
|
|
pub no_of_balls: u32,
|
|
}
|
|
|
|
impl CommandLineArguments {
|
|
/**
|
|
* # Summary
|
|
* Creates a new instance of a CommandLineArguments object either from
|
|
* the command line or the default configuration
|
|
*
|
|
* # Returns
|
|
* A new ```CommandLineArguments``` object
|
|
*
|
|
* # Examples
|
|
*
|
|
* ```rust
|
|
* let cmdargs = CommandLineArguments::new();
|
|
* ```
|
|
*/
|
|
pub fn new() -> CommandLineArguments {
|
|
let matches = CommandLineArguments::parse_command_line();
|
|
|
|
CommandLineArguments {
|
|
no_of_balls: FromStr::from_str(matches.value_of("NOOFBALLS").unwrap_or("1000"))
|
|
.unwrap(),
|
|
}
|
|
}
|
|
|
|
/**
|
|
* # Summary
|
|
* Parses the command line and returns all matches that fit valid options.
|
|
*
|
|
* # Generics
|
|
* ## Lifetimeparm: 'a
|
|
* Assures the same lifetime to the return value than the command line.
|
|
*
|
|
* # Returns
|
|
* An *ArgMatches* struct, that contrains all matched arguments.
|
|
*/
|
|
fn parse_command_line<'a>() -> ArgMatches<'a> {
|
|
clap_app!(myapp =>
|
|
(version: "1.0.360.1")
|
|
(author: "Jali <jali@orca-central.de>")
|
|
(about: "A naïve algorithm to sort balls in a ballpit by colour")
|
|
(@arg NOOFBALLS: -n --noofballs +takes_value "Specifies the number of balls in the ballpit")
|
|
)
|
|
.get_matches()
|
|
}
|
|
}
|