Jump to content

Interactive programming (repl): Difference between revisions

Line 1,402:
 
=={{header|Rust}}==
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.
** First, create the cli.yaml file to hold the CLI options, but it could be called anything we like:
<lang yaml>
name: myapp
version: "1.0"
author: A Rust Developer <rustme@home.com>
about: Does awesome things
args:
- STRING1:
about: First string to use
required: true
index: 1
- STRING2:
about: Second string to use
required: true
index: 2
- SEPARATOR:
about: Separtor to use
required: true
index: 3
</lang>
** Then, simply add ''clap'' the ''yaml'' feature flag to your Cargo.toml.
<lang yaml>
[dependencies]
clap = { version = "3.0.0-beta.2", features = ["yaml"] }
</lang>
** Enter this code in Rust source file
<lang rust>
use std::env;
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.