No description
Find a file
2023-01-27 20:40:53 +08:00
.github/workflows ci: update CI 2022-11-12 11:22:29 +08:00
examples chore: add sub_subcommands example and nu script to generate readme dynamically 2022-11-11 22:06:06 +08:00
scripts docs: update build badge 2023-01-24 16:17:31 +08:00
src ci: clippy fix 2023-01-27 19:51:48 +08:00
tests ci: fix tests 2023-01-24 16:31:58 +08:00
.gitignore ci: fix tests 2023-01-24 16:31:58 +08:00
Cargo.lock chore: release 0.1.10 2023-01-27 20:40:53 +08:00
Cargo.toml chore: release 0.1.10 2023-01-27 20:40:53 +08:00
LICENSE chore: release 0.1.0 2022-11-11 21:35:21 +08:00
README.md ci: fix tests 2023-01-24 16:31:58 +08:00

clap_complete_nushell

Generates Nushell completions for clap based CLIs

Crates.io Crates.io License docs.rs Build Status GitHub last commit

Examples

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 *