Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/frol/clap-yaml-json-demo
Minimal CLI app in Rust that does yaml to json and json to yaml convertion
https://github.com/frol/clap-yaml-json-demo
Last synced: 14 days ago
JSON representation
Minimal CLI app in Rust that does yaml to json and json to yaml convertion
- Host: GitHub
- URL: https://github.com/frol/clap-yaml-json-demo
- Owner: frol
- Created: 2023-04-01T08:02:55.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-02T20:10:02.000Z (almost 2 years ago)
- Last Synced: 2024-11-01T01:42:13.455Z (2 months ago)
- Language: Rust
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Demo YAML to JSON and JSON to YAML command line utility
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`](https://github.com/frol/clap-yaml-json-demo/tree/main) - lazy and short version without proper error handling
* [`with-error-handling`](https://github.com/frol/clap-yaml-json-demo/tree/with-error-handling) - added the error handling
* [`with-custom-type`](https://github.com/frol/clap-yaml-json-demo/tree/with-custom-type) - added a custom type `ExistingPath` to showcase that you can validate anything at CLI arguments parsing[![asciicast](https://asciinema.org/a/GHMTURjyGxh3AqN1V4bUYj8ht.svg)](https://asciinema.org/a/GHMTURjyGxh3AqN1V4bUYj8ht)
## Build
You will need [Rust](https://www.rust-lang.org/) installed on your computer, and then run:
```sh
cargo build --release
```## Run
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).