From 5b90c286642efa13405e14ae33e54a229900ac13 Mon Sep 17 00:00:00 2001 From: Ophir LOJKINE Date: Sun, 25 Aug 2019 22:16:29 +0200 Subject: [PATCH 1/2] Update keyvalue example See #233 --- examples/keyvalue.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/keyvalue.rs b/examples/keyvalue.rs index 31fc2214..b351735c 100644 --- a/examples/keyvalue.rs +++ b/examples/keyvalue.rs @@ -1,6 +1,7 @@ use std::error::Error; use structopt::StructOpt; +/// Parse a single key-value pair fn parse_key_val(s: &str) -> Result<(T, U), Box> where T: std::str::FromStr, @@ -16,7 +17,14 @@ where #[derive(StructOpt, Debug)] struct Opt { - #[structopt(short = "D", parse(try_from_str = parse_key_val))] + // number_of_values = 1 forces the user to repeat the -D option for each key-value pair: + // my_program -D a=1 -D b=2 + // Without number_of_values = 1 you can do: + // my_program -D a=1 b=2 + // but this makes adding an argument after the values impossible: + // my_program -D a=1 -D b=2 my_input_file + // becomes invalid. + #[structopt(short = "D", parse(try_from_str = parse_key_val), number_of_values = 1)] defines: Vec<(String, i32)>, } From 7bb0f4e7e088b47651c40abeec68545f5a202af2 Mon Sep 17 00:00:00 2001 From: Ophir LOJKINE Date: Sun, 25 Aug 2019 22:31:23 +0200 Subject: [PATCH 2/2] fix rustfmt --- examples/keyvalue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/keyvalue.rs b/examples/keyvalue.rs index b351735c..231aea07 100644 --- a/examples/keyvalue.rs +++ b/examples/keyvalue.rs @@ -18,7 +18,7 @@ where #[derive(StructOpt, Debug)] struct Opt { // number_of_values = 1 forces the user to repeat the -D option for each key-value pair: - // my_program -D a=1 -D b=2 + // my_program -D a=1 -D b=2 // Without number_of_values = 1 you can do: // my_program -D a=1 b=2 // but this makes adding an argument after the values impossible: