Skip to content

Commit

Permalink
Merge pull request #267 from ClockworksIO/expose_options
Browse files Browse the repository at this point in the history
Add Configuration::options
  • Loading branch information
frankmcsherry committed Apr 26, 2019
2 parents 23a66da + 2016147 commit 6d75370
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions communication/src/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,25 @@ pub enum Configuration {
#[cfg(feature = "getopts")]
impl Configuration {

/// Constructs a new configuration by parsing supplied text arguments.
///
/// Most commonly, this uses `std::env::Args()` as the supplied iterator.
pub fn from_args<I: Iterator<Item=String>>(args: I) -> Result<Configuration,String> {

/// Returns a `getopts::Options` struct that can be used to print
/// usage information in higher-level systems.
pub fn options() -> getopts::Options {
let mut opts = getopts::Options::new();
opts.optopt("w", "threads", "number of per-process worker threads", "NUM");
opts.optopt("p", "process", "identity of this process", "IDX");
opts.optopt("n", "processes", "number of processes", "NUM");
opts.optopt("h", "hostfile", "text file whose lines are process addresses", "FILE");
opts.optflag("r", "report", "reports connection progress");

opts
}

/// Constructs a new configuration by parsing supplied text arguments.
///
/// Most commonly, this uses `std::env::Args()` as the supplied iterator.
pub fn from_args<I: Iterator<Item=String>>(args: I) -> Result<Configuration,String> {
let opts = Configuration::options();

opts.parse(args)
.map_err(|e| format!("{:?}", e))
.map(|matches| {
Expand Down

0 comments on commit 6d75370

Please sign in to comment.