In this demo I just wanted to show that developing CLIs in Rust is a breeze.
There are three versions of this demo stored in separate branches:
main
- lazy and short version without proper error handlingwith-error-handling
- added the error handlingwith-custom-type
- added a custom typeExistingPath
to showcase that you can validate anything at CLI arguments parsing
You will need Rust installed on your computer, and then run:
cargo build --release
After the build, the executable file is usually located at target/release/clap-yaml-json-demo
(or with .exe
extension on Windows), so run it:
On Linux/MacOS:
./target/release/clap-yaml-json-demo
On Windows:
.\target\release\clap-yaml-json-demo.exe
You will be greeted with clap help message that is generated automatically from the code!
All the CLI arguments are validated and once you get the Command
type, you can trust that all the types are valid (e.g. if you expect a number, it will be a number, not a string that you will still need to parse).