Anonymous user
Interactive programming (repl): Difference between revisions
→{{header|Rust}}
Line 1,404:
This method use the crate clap: '''clap''' is used to parse and validate the string of command line arguments provided by the user at runtime. You provide the list of valid possibilities, and clap handles the rest. This means you focus on your applications functionality, and less on the parsing and validating of arguments.
* One of clap configurations is a mathod used a YAML file to build the CLI and keep the Rust source tidy or support multiple localized translations by having different YAML files for each localization.
<lang yaml>
name: myapp
Line 1,424:
index: 3
</lang>
<lang yaml>
[dependencies]
clap = { version = "3.0.0-beta.2", features = ["yaml"] }
</lang>
<lang rust>
#[macro_use]
use std::env;▼
extern crate clap;
fn main() {
let
let matches = App::from(yaml).get_matches();
println!("{:?}", f(&args[1], &args[2], &args[3]));▼
let str1 = matches.value_of("STRING1").unwrap();
let str2 = matches.value_of("STRING2").unwrap();
let str3 = matches.value_of("SEPARATOR").unwrap();
}
fn f<'a>(s1: &'a str, s2: &'a str, sep :&'a str) -> String{
[s1,sep,sep,s2].iter().map(|x| *x).collect()
}</lang>▼
▲</lang>
Output:
<pre>
|