14 个版本

0.1.13 2023 年 9 月 9 日
0.1.12 2023 年 9 月 9 日
0.1.9 2022 年 10 月 27 日

366命令行界面

30 每月下载
3 crates 中使用

MIT 许可证

13KB
199

简单易用、高效的命令行参数解析器

Crates.io Rust license

示例

创建 cli.json

{
    "name":"cargo",
    "version":"1.0.0",
    "authors":["andrew <[email protected]>","ryan <[email protected]>"],
    "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()
    }
}

一个简单的 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

依赖项

~520KB