11 个版本 (1 个稳定版)

1.0.0 2024 年 3 月 12 日
0.1.12 2023 年 7 月 17 日
0.1.11 2023 年 3 月 25 日
0.1.9 2022 年 10 月 24 日

#254命令行界面

Download history 171/week @ 2024-03-11 23/week @ 2024-03-18 10/week @ 2024-03-25 50/week @ 2024-04-01 9/week @ 2024-04-08 15/week @ 2024-04-15 15/week @ 2024-04-22 8/week @ 2024-04-29 15/week @ 2024-05-06 35/week @ 2024-05-13 55/week @ 2024-05-20 55/week @ 2024-05-27 44/week @ 2024-06-03 38/week @ 2024-06-10 35/week @ 2024-06-17 50/week @ 2024-06-24

171 每月下载量
用于 7 个crate (2 个直接使用)

MIT 许可证

13KB
229

carapace-spec-clap

Crates.io

规范 生成 clap-rs/clap

asciicast

use carapace_spec_clap::Spec;
use clap::{Arg, ArgAction, Command, ValueHint};
use clap_complete::generate;
use std::io;

fn main() {
    let mut cmd = Command::new("example")
        .aliases(["alias1", "alias2"])
        .about("example command")
        .arg(
            Arg::new("help")
                .long("help")
                .short('h')
                .help("show help")
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new("optional")
                .long("optional")
                .help("optional argument")
                .require_equals(true)
                .value_hint(ValueHint::Username),
        )
        .arg(
            Arg::new("value")
                .short('v')
                .help("takes argument")
                .value_parser(["one", "two", "three"]),
        )
        .subcommand(
            Command::new("subcommand")
                .about("example subcommand")
                .arg(
                    Arg::new("command")
                        .long("command")
                        .short('c')
                        .help("execute command")
                        .value_hint(ValueHint::CommandName),
                )
                .arg(
                    Arg::new("pos1")
                        .value_parser(["four", "five", "six"])
                        .value_hint(ValueHint::DirPath),
                )
                .arg(
                    Arg::new("posAny")
                        .num_args(1..)
                        .value_hint(ValueHint::Hostname),
                ),
        );

    generate(Spec, &mut cmd, "example", &mut io::stdout());
}
name: example
aliases:
- alias1
- alias2
description: example command
flags:
  -h, --help: show help
  --optional?: optional argument
  -v=: takes argument
completion:
  flag:
    optional:
    - $_os.Users
    v:
    - one
    - two
    - three
commands:
- name: subcommand
  description: example subcommand
  flags:
    -c, --command=: execute command
  completion:
    flag:
      command:
      - $_os.PathExecutables
      - $files
    positional:
    - - $directories
      - four
      - five
      - six
    positionalany:
    - $_net.Hosts

依赖项

~4MB
~75K SLoC