我正在尝试添加另一个打印解析结果的参数,但不确定为什么会导致此错误:
src/main.rs:35:32
|
35 | println!("{:#?}", matches, if printparsed{ "" } else { "Cannot Parse Output"});
| ------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument never used
代码在这里:
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"});
}