Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0ncorhynchus/entrance
A library for parsing command line arguments
https://github.com/0ncorhynchus/entrance
command-line-parser rust
Last synced: 3 months ago
JSON representation
A library for parsing command line arguments
- Host: GitHub
- URL: https://github.com/0ncorhynchus/entrance
- Owner: 0ncorhynchus
- License: mit
- Created: 2019-05-22T16:09:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-14T07:38:27.000Z (almost 4 years ago)
- Last Synced: 2024-10-09T14:45:29.421Z (4 months ago)
- Topics: command-line-parser, rust
- Language: Rust
- Homepage:
- Size: 135 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
entrance
========[![Crates.io](https://img.shields.io/crates/v/entrance.svg)](https://crates.io/crates/entrance)
[![Document](https://docs.rs/entrance/badge.svg)](https://docs.rs/entrance)
[![CircleCI](https://circleci.com/gh/0ncorhynchus/entrance.svg?style=shield)](https://circleci.com/gh/0ncorhynchus/entrance)Type sytem assisted command line argument parser
`entrance` provides type assisted tools for parsing command line arguments.
Simple usage
------------```rust
use entrance::{Arguments, Options};
use std::env;
use std::path::PathBuf;#[derive(Options, PartialEq)]
enum Opts {
#[entrance(description = "Print help message")]
#[entrance(short = 'h')]
#[entrance(informative(entrance::help))]
Help,#[entrance(description = "Print version infomation")]
#[entrance(informative(entrance::version))]
Version,#[entrance(description = "Use verbose output")]
#[entrance(short = 'v')]
Verbose,
}#[derive(Arguments)]
struct Args {
#[entrance(description = "The number of lines")]
num: f64,#[entrance(description = "Path to a file")]
file: PathBuf,
}type Command = entrance::Command;
fn main() {
let command = Command::new(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
let (opts, args) = command.parse_or_exit(env::args());if opts.contains(&Opts::Verbose) {
println!("enabled the verbose output");
}println!("1st argument: \"{}\"", args.num);
println!("2nd argument: \"{}\"", args.file.display());
}
```Structs and traits
------------------### Command
This struct provides tools for parsing command line arguments.
Before parsing command line arguments, it is necessary to create the instance
with the associated function `new` then, call `parse` of the instance.### Options
A derive macro is available for this.
Limitation: the derive macro supports only an Enum whose variants don't have any field.
### Arguments
A derive macro is available for this.
Limitation: the macro supports only the struct with members implementing `FromStr`.