10 releases
0.1.9 | Oct 27, 2022 |
---|---|
0.1.8 | Oct 27, 2022 |
#246 in Command-line interface
70 downloads per month
Used in 2 crates
11KB
124 lines
A simple to use, efficient, Command Line Argument Parser
Example
create cli.json
{
"name":"git",
"version":"0.1.1",
"authors":["Anonymous <dnrops@anonymous.com>"],
"about":"A git cli",
"args":[
{
"arg":"--init",
"short":"-i",
"required":false,
"about":"Create an empty Git repository or reinitialize an existing one",
"takes_value":true
},
{
"arg":"--add",
"short":"-a",
"required":false,
"about":"Add file contents to the index",
"takes_value":true
},
{
"arg":"--commit",
"short":"-c",
"required":false,
"about":"Record changes to the repository",
"takes_value":true,
"subcommands":[
{
"arg":"--message",
"short":"-m",
"required":false,
"about":"commit message",
"takes_value":true
},
{
"arg":"--file",
"short":"-F",
"required":false,
"about":"read message from file",
"takes_value":true
}
]
},
{
"arg":"--push",
"short":"-p",
"required":false,
"about":"Update remote refs along with associated objects",
"takes_value":true
},
{
"arg":"--pull",
"short":" ",
"required":false,
"about":"Update remote refs along with associated objects",
"takes_value":true
},
{
"arg":"status",
"short":"-s",
"required":false,
"about":"Show the working tree status",
"takes_value":true
}
]
}
cargo add cok
main.rs
#[allow(warnings)]
fn main() {
use cok::cli::Cli;
let json = include_str!("../cli.json");
Cli::load_from_json(json);
let args = Cli::args();
}
a simple cli
git 0.1.1
Anonymous <dnrops@anonymous.com>
A git cli
USAGE:
OPTION REQUIRED ABOUT
git -i --init false Create an empty Git repository or reinitialize an existing one
git -a --add false Add file contents to the index
git -c --commit false Record changes to the repository
git -p --push false Update remote refs along with associated objects
git --pull false Update remote refs along with associated objects
git -s status false Show the working tree status
git -h --help Prints help information
SUBCOMMANDS:
OPTION SUBCOMMAND REQUIRED ABOUT
git -c --commit -m --message false commit message
git -c --commit -F --file false read message from file
Dependencies
~1MB
~20K SLoC