Crates.io | zgclp |
lib.rs | zgclp |
version | 0.3.1 |
source | src |
created_at | 2021-10-30 17:24:52.875102 |
updated_at | 2022-03-30 12:21:37.371252 |
description | Zgclp (Zero-grammar definition command-line parser) |
homepage | https://github.com/tos-kamiya/zgclp |
repository | |
max_upload_size | |
id | 474444 |
size | 21,645 |
** DISCONTINUED**: Please use ng-clp instead.
Zgclp (Zero-grammar definition command-line parser) is one of Rust's command-line parsers. A normal command-line parser generates a parser from the definition of command-line options that accepts a command line according to its grammar. In contrast, zgclp uses a universal parser to discover what it assumes to be options or arguments from the given command-line arguments.
You can build the sample program with "cargo build" and try it as follows:
$ cargo build
$ target/debug/zgclp foo -bar bal --bra boo
Argument "foo" .
Option "-b" with argument "ar" .
Argument "bal" .
Option "--bra" with argument "boo" .
When you write a single letter of the alphabet as A, B, etc., zgclp accepts the following options.
Format | Parsed |
---|---|
-A |
Option with no argument -A . |
-A BC |
Option -A with argument BC . |
-ABC |
Option -A with argument BC . |
--AB |
Option with no arguments --AB . |
--AB CD |
Option --AB with the argument CD . |
--AB=CD |
Option --AB with argument CD . |
-- |
Separator. |
"But isn't that ambiguous?" If you are wondering, you are correct.
When the command line is
-a bc
zgclp will output the following two interpretations.
-a
appears with no arguments (the next bc
is a normal command-line argument that has nothing to do with the option -a
).-a
appears with the argument bc
.Short Answer:
Copy the boilerplate code examples/zgclp_boilerplate.rs as your main.rs
and modify it.
Long Answer:
Call the function arg_parse
, giving the command-line arguments as an array of strings (&[&str]
) and the starting position of parsing.
The return value is a tuple with three values.
Use arg_parse
to do a "full" parsing of options and (normal) arguments, including the order of their appearance.
If you don't need such full parsing and it is enough to just get the values for normal arguments, consider using arg_parse_a
or arg_parse_ahv
.
See a sample code src/main.rs for arg_parse
or a boilerplate examples/zgclp_boilerplate.rs for arg_parse_ahv
.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.