#clap #completion #nushell #arguments-parser #cli

clap_complete_nushell

用于 Nushell 完成脚本的 clap 生成库

22 个版本 (10 个稳定版本)

4.5.3 2024 年 7 月 25 日
4.5.1 2024 年 2 月 16 日
4.4.2 2023 年 10 月 24 日
4.3.1 2023 年 6 月 2 日
0.1.8 2022 年 11 月 5 日

#282命令行界面

Download history 18024/week @ 2024-04-15 17677/week @ 2024-04-22 17702/week @ 2024-04-29 20881/week @ 2024-05-06 20820/week @ 2024-05-13 19873/week @ 2024-05-20 18083/week @ 2024-05-27 22065/week @ 2024-06-03 21113/week @ 2024-06-10 20745/week @ 2024-06-17 26619/week @ 2024-06-24 22144/week @ 2024-07-01 21824/week @ 2024-07-08 24878/week @ 2024-07-15 30744/week @ 2024-07-22 28837/week @ 2024-07-29

每月 108,072 次下载
用于 42 个 crate (35 个直接使用)

MIT/Apache

245KB
3K SLoC

clap_complete_nushell

为基于 clap 的 CLI 生成 Nushell 完成项

Crates.io Crates.io License License docs.rs

示例

myapp.rs

use clap::{builder::PossibleValue, Arg, ArgAction, Command, ValueHint};
use clap_complete::generate;
use clap_complete_nushell::Nushell;
use std::io;

fn main() {
    let mut cmd = Command::new("myapp")
        .version("3.0")
        .propagate_version(true)
        .about("Tests completions")
        .arg(
            Arg::new("file")
                .value_hint(ValueHint::FilePath)
                .help("some input file"),
        )
        .arg(
            Arg::new("config")
                .action(ArgAction::Count)
                .help("some config file")
                .short('c')
                .visible_short_alias('C')
                .long("config")
                .visible_alias("conf"),
        )
        .arg(Arg::new("choice").value_parser(["first", "second"]))
        .subcommand(
            Command::new("test").about("tests things").arg(
                Arg::new("case")
                    .long("case")
                    .action(ArgAction::Set)
                    .help("the case to test"),
            ),
        )
        .subcommand(
            Command::new("some_cmd")
                .about("top level subcommand")
                .subcommand(
                    Command::new("sub_cmd").about("sub-subcommand").arg(
                        Arg::new("config")
                            .long("config")
                            .action(ArgAction::Set)
                            .value_parser([PossibleValue::new("Lest quotes aren't escaped.")])
                            .help("the other case to test"),
                    ),
                ),
        );

    generate(Nushell, &mut cmd, "myapp", &mut io::stdout());
}

myapp.nu

module completions {

  def "nu-complete myapp choice" [] {
    [ "first" "second" ]
  }

  # Tests completions
  export extern myapp [
    file?: string             # some input file
    --config(-c)              # some config file
    --conf                    # some config file
    -C                        # some config file
    choice?: string@"nu-complete myapp choice"
    --version(-V)             # Print version
  ]

  # tests things
  export extern "myapp test" [
    --case: string            # the case to test
    --version(-V)             # Print version
  ]

  # top level subcommand
  export extern "myapp some_cmd" [
    --version(-V)             # Print version
  ]

  def "nu-complete myapp some_cmd sub_cmd config" [] {
    [ "\"Lest quotes aren't escaped.\"" ]
  }

  # sub-subcommand
  export extern "myapp some_cmd sub_cmd" [
    --config: string@"nu-complete myapp some_cmd sub_cmd config" # the other case to test
    --version(-V)             # Print version
  ]

}

use completions *

依赖

~1MB
~15K SLoC