14 releases

0.1.13 Sep 9, 2023
0.1.12 Sep 9, 2023
0.1.9 Oct 27, 2022

#357 in Command-line interface

35 downloads per month
Used in 3 crates

MIT license

13KB
199 lines

A simple to use, efficient, Command Line Argument Parser

Crates.io Rust license

Example

create cli.json

{
    "name":"cargo",
    "version":"1.0.0",
    "authors":["andrew <dnrops@anonymous.com>","ryan <rysn@gmail.com>"],
    "description":"Rust's package manager",
    "options":[
        {
            "name":"--version",
            "short":"V",
            "description":"Print version info and exit"
        },
        {
            "name":"--offline",
            "description":"Run without accessing the network"
        }
    ],
    "commands":[
        {
            "name":"build",
            "short":"b",
            "description":"Compile the current package"
        },
        {
            "name":"check",
            "short":"c",
            "description":"Analyze the current package and report errors, but don't build object files"
        },
        {
            "name":"clean",
            "description":"Remove the target directory"
        },
        {
            "name":"new",
            "description":"Create a new cargo package"
        },
        {
            "name":"add",
            "description":"Add dependencies to a manifest file"
        }
    ]
}
cargo add cok

main.rs

fn main() {
    use cok::Cli;
    let json = include_str!("../cli.json");
    let cli = Cli::new(json);
    let args = cli.args();
    if args.len() !=3{
        cli.print_help()
    }
}

a simple cli

cargo 1.0.0
andrew <dnrops@anonymous.com>,ryan <rysn@gmail.com>
Rust's package manager

Usage: cargo [OPTIONS] [COMMAND]

Options:
cargo   build, b        Compile the current package
cargo   check, c        Analyze the current package and report errors, but don't build object files
cargo   clean           Remove the target directory
cargo   new             Create a new cargo package
cargo   add             Add dependencies to a manifest file

Commands:
cargo   build, b        Compile the current package
cargo   check, c        Analyze the current package and report errors, but don't build object files
cargo   clean           Remove the target directory
cargo   new             Create a new cargo package
cargo   add             Add dependencies to a manifest file
cargo   -h --help       Prints help information

Dependencies

~485KB