Reputation: 161
I am trying to just add another argument that prints the parsed results, not sure why this is resulting in this error:
src/main.rs:35:32
|
35 | println!("{:#?}", matches, if printparsed{ "" } else { "Cannot Parse Output"});
| ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument never used
Code here:
use clap::{App, Arg};
fn main() {
let matches = App::new("rustecho")
.version("0.1.0")
.author("ElementalX")
.about("echo")
.bin_name("rustecho")
.usage("rustecho <SOMETEXTHERE>")
.arg(
Arg::with_name("outputtext")
.value_name("TEXT")
.help("Input text")
.required(true)
.min_values(1),
)
.arg(
Arg::with_name("omitnewline")
.short("n")
.help("Do not print newline")
.takes_value(false),
)
.arg(
Arg::with_name("parseoutput")
.short("p")
.help("Parse the arguments and print them"),
)
.get_matches();
let text = matches.values_of_lossy("outputtext").unwrap();
let omit_newline = matches.is_present("omitnewline");
let mut parsedargs = matches.values_of_lossy("parseoutput").unwrap();
let mut printparsed = matches.is_present("parseoutput");
println!("{:#?}", matches, if printparsed{ "" } else { "Cannot Parse Output"});
print!("{}{}", text.join(" "), if omit_newline{ "" } else { "\n"});
}
Upvotes: 0
Views: 748
Reputation: 24797
You are using one format specifier(#?
) with two arguments. If you intended to pretty print both matches
and the string(based on the condition), you can wrap it in a tuple.
println!("{:#?}", (matches, if printparsed{ "" } else { "Cannot Parse Output"}));
Alternatively you can use multiple format specifiers.
println!("{:#?} {}", matches, if printparsed{ "" } else { "Cannot Parse Output"});
Upvotes: 2