Crates.io | arg_parse |
lib.rs | arg_parse |
version | 0.3.0 |
source | src |
created_at | 2023-01-03 00:55:42.773602 |
updated_at | 2023-01-05 22:03:31.600405 |
description | A tool to parse console or your own arguments, without dependencies. |
homepage | |
repository | https://github.com/oxydemeton/arg_parse/ |
max_upload_size | |
id | 749780 |
size | 38,547 |
The interface for developer is work in progress. So expect minor and major changes when updating until v1.0
arg_parse is a tool to simplify the processing of command line arguments. It doesn't have any dependencies and the initialization is done at compile time.
short options
(Values set with --
which default is false and set to true by being used.)long options
(Values mentioned after -
which have their value(as a string) followed)non options
(Single Values parameters without any prefix )sub commands
(which only one can be used and all following arguments are related to)Add arg_parse = "0.3.0"
to your cargo dependencies (cargo.toml
).
[dependencies]
arg_parse = "0.3.0"
Prints the Options which are found or parsing errors.
Arguments:
hello
without any further argumentsb
with two argumentsa
without any argumentsuse arg_parse::ArgParser;
use arg_parse::config;
//List of all available long options
const LONG_OPTIONS: &'static [config::LongOption] = &[
//Define a long option called hello without parameters
config::LongOption{name: "hello", value_count: 0}
];
//List of all available short options
const SHORT_OPTIONS: &'static [config::ShortOption] = &[
//Define a short option called b with two parameters
config::ShortOption{name:'b', value_count: 2},
//Define a short option called a without parameters
config::ShortOption{name:'a', value_count: 0}
];
const NON_OPTIONS: &'static [config::NonOption] = &[
//Define a non option called non-option with three parameters
config::NonOption{name: "non-option", value_count: 3},
//Define a short option called a without parameters
config::NonOption{name:"last-option", value_count: 0}
];
//Create the root command which is the program itself basically
const PARSER_ROOT_CMD: config::Config = config::Config::from(SHORT_OPTIONS, LONG_OPTIONS, NON_OPTIONS);
//Create the parser from the root command
static PARSER: ArgParser = ArgParser::from(PARSER_ROOT_CMD);
fn main() {
let root_cmd = PARSER.parse(); //Parse the command line arguments
match root_cmd {
Ok(result) => println!("Result: {:?}", result), //Print result
Err(error) => println!("ERROR: {:?}", error) //Print errors if occur
}
}