2022-10-22 15:27:04 +00:00
# clap_complete_nushell
Generates [Nushell ](https://github.com/nushell/nushell ) completions for [`clap` ](https://github.com/clap-rs/clap ) based CLIs
2022-11-01 04:04:45 +00:00
[![Crates.io ](https://img.shields.io/crates/v/clap_complete_nushell )](https://crates.io/crates/clap_complete_nushell)
[![Crates.io ](https://img.shields.io/crates/d/clap_complete_nushell )](https://crates.io/crates/clap_complete_nushell)
2023-05-23 05:21:43 +00:00
[![License ](https://img.shields.io/badge/license-Apache%202.0-blue )](LICENSE-APACHE)
[![License ](https://img.shields.io/badge/license-MIT-blue )](LICENSE-MIT)
2022-11-01 04:04:45 +00:00
[![docs.rs ](https://img.shields.io/docsrs/clap_complete_nushell )](https://docs.rs/clap_complete_nushell)
2023-01-24 08:15:08 +00:00
[![Build Status ](https://img.shields.io/github/actions/workflow/status/nibon7/clap_complete_nushell/ci.yml )](https://github.com/nibon7/clap_complete_nushell/actions/workflows/ci.yml?query=branch%3Amain)
2022-11-07 09:42:57 +00:00
[![GitHub last commit ](https://img.shields.io/github/last-commit/nibon7/clap_complete_nushell )](https://github.com/nibon7/clap_complete_nushell/commits/main)
2022-11-01 04:04:45 +00:00
2022-10-22 15:27:04 +00:00
## Examples
### myapp.rs
```rust
2022-11-02 03:59:33 +00:00
use clap::{builder::PossibleValue, Arg, ArgAction, Command, ValueHint};
2022-10-22 15:27:04 +00:00
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")
2022-11-02 03:59:33 +00:00
.value_hint(ValueHint::FilePath)
2022-10-22 15:27:04 +00:00
.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)
2022-11-02 03:59:33 +00:00
.value_parser([PossibleValue::new("Lest quotes aren't escaped.")])
2022-10-22 15:27:04 +00:00
.help("the other case to test"),
),
),
);
generate(Nushell, & mut cmd, "myapp", & mut io::stdout());
}
2023-01-24 08:15:08 +00:00
2022-10-22 15:27:04 +00:00
```
### myapp.nu
```nu
module completions {
2022-11-01 04:03:16 +00:00
def "nu-complete myapp choice" [] {
2022-10-31 12:11:01 +00:00
[ "first" "second" ]
}
2022-10-22 15:27:04 +00:00
# Tests completions
export extern myapp [
2022-11-02 10:40:20 +00:00
file?: string # some input file
--config(-c) # some config file
--conf # some config file
-C # some config file
2022-11-01 04:03:16 +00:00
choice?: string@"nu-complete myapp choice"
2023-01-24 08:26:54 +00:00
--version(-V) # Print version
2022-10-22 15:27:04 +00:00
]
# tests things
export extern "myapp test" [
2022-11-02 10:40:20 +00:00
--case: string # the case to test
2023-01-24 08:26:54 +00:00
--version(-V) # Print version
2022-10-22 15:27:04 +00:00
]
# top level subcommand
export extern "myapp some_cmd" [
2023-01-24 08:26:54 +00:00
--version(-V) # Print version
2022-10-22 15:27:04 +00:00
]
2022-11-01 04:03:16 +00:00
def "nu-complete myapp some_cmd sub_cmd config" [] {
2022-11-02 03:59:33 +00:00
[ "\"Lest quotes aren't escaped.\"" ]
2022-10-31 12:11:01 +00:00
}
2022-10-22 15:27:04 +00:00
# sub-subcommand
export extern "myapp some_cmd sub_cmd" [
2022-11-02 10:40:20 +00:00
--config: string@"nu-complete myapp some_cmd sub_cmd config" # the other case to test
2023-01-24 08:26:54 +00:00
--version(-V) # Print version
2022-10-22 15:27:04 +00:00
]
}
use completions *
```