-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from sebastianconcept/minor-review
Minor review
- Loading branch information
Showing
10 changed files
with
264 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ Cargo.lock | |
# Added by cargo | ||
|
||
/target | ||
|
||
output.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
extern crate clap; | ||
use clap::{value_parser, Arg, ArgAction, ArgMatches, Command}; | ||
use clap::{value_parser, Arg, ArgAction, ArgGroup, ArgMatches, Command}; | ||
|
||
pub fn get_socket_address() -> String { | ||
let args = get_arguments(); | ||
|
@@ -14,14 +14,23 @@ pub fn get_socket_address() -> String { | |
format!("{}:{}", bind, port) | ||
} | ||
|
||
pub fn get_bench_and_payload() -> (Option<usize>, Option<String>) { | ||
let args = get_arguments(); | ||
let times = args.get_one("bench").copied(); | ||
let payload = args.get_one("payload").cloned(); | ||
(times, payload) | ||
} | ||
|
||
fn get_arguments<'a>() -> ArgMatches { | ||
Command::new("Memoizer") | ||
.version("1.0") | ||
.version("0.1.2") | ||
.author("Sebastian Sastre <[email protected]>") | ||
.about("Minimalist thread-safe key-value store shared over TCP sockets.") | ||
.arg( | ||
Arg::with_name("bind") | ||
.value_name("IP_ADDRESS") | ||
.short('b') | ||
.long("bind") | ||
.multiple(false) | ||
.action(ArgAction::Append) | ||
.value_parser(value_parser!(String)) | ||
|
@@ -31,13 +40,51 @@ fn get_arguments<'a>() -> ArgMatches { | |
) | ||
.arg( | ||
Arg::with_name("port") | ||
.value_name("PORT") | ||
.short('p') | ||
.long("port") | ||
.multiple(false) | ||
.action(ArgAction::Append) | ||
.value_parser(value_parser!(String)) | ||
.help("Defines the port to use.") | ||
.required(true) | ||
.takes_value(true), | ||
) | ||
.arg( | ||
Arg::with_name("bench") | ||
.value_name("NUM_TIMES") | ||
.short('e') | ||
.long("bench") | ||
.multiple(false) | ||
.action(ArgAction::Append) | ||
.value_parser(value_parser!(usize)) | ||
.help("Runs a benchmark a number of times with an optional custom payload") | ||
.required(false) | ||
.takes_value(true), | ||
) | ||
.arg( | ||
Arg::with_name("payload") | ||
.value_name("CUSTOM_PAYLOAD") | ||
.short('d') | ||
.long("payload") | ||
.multiple(false) | ||
.action(ArgAction::Append) | ||
.value_parser(value_parser!(String)) | ||
.help("The custom payload to use in a benchmark") | ||
.required(false) | ||
.takes_value(true), | ||
) | ||
.group( | ||
ArgGroup::with_name("bench_options") | ||
.args(&["bench", "payload"]) | ||
.multiple(true) | ||
.required(false), // Either times or string is required | ||
) | ||
.group( | ||
ArgGroup::with_name("connection_options") | ||
.args(&["bind", "port"]) | ||
.multiple(true) | ||
.required(false), // bind and port are required unless bench is selected | ||
) | ||
.get_matches() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.