#arg #parse #parser #cli #argument

bin+lib cok

A simple to use, efficient, Command Line Argument Parser

10 releases

0.1.9 Oct 27, 2022
0.1.8 Oct 27, 2022

#246 in Command-line interface

Download history 13/week @ 2022-11-28 28/week @ 2022-12-05 34/week @ 2022-12-12 17/week @ 2022-12-19 11/week @ 2022-12-26 6/week @ 2023-01-02 21/week @ 2023-01-09 6/week @ 2023-01-16 16/week @ 2023-01-23 46/week @ 2023-01-30 12/week @ 2023-02-06 44/week @ 2023-02-13 28/week @ 2023-02-20 22/week @ 2023-02-27 10/week @ 2023-03-06 6/week @ 2023-03-13

70 downloads per month
Used in 2 crates

MIT license

11KB
124 lines

A simple to use, efficient, Command Line Argument Parser

Crates.io Rust license

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