summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSebastian Holmin <sebastian.holmin@mullvad.net>2023-11-09 15:05:03 +0100
committerSebastian Holmin <sebastian.holmin@mullvad.net>2025-02-24 16:59:44 +0100
commit7a4eb09533a529bddeec479fd6833de4525cfa6d (patch)
tree4e32453ad7178f491391f0731251943fc96936da
parent4dd8c35fa54f1cce75b713daea4536245798a7ba (diff)
downloadmullvadvpn-nushell_completions.tar.xz
mullvadvpn-nushell_completions.zip
First test with clap_complete_nushell cratenushell_completions
Generate the shell completions and print to stdout. The completions can be manually activated by pasting the contents in your config.nu and adding '`export use completions *`'.
-rw-r--r--Cargo.lock11
-rw-r--r--mullvad-cli/Cargo.toml5
-rw-r--r--mullvad-cli/src/main.rs22
3 files changed, 30 insertions, 8 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4afca015ea..07de6d58b4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -557,6 +557,16 @@ dependencies = [
]
[[package]]
+name = "clap_complete_nushell"
+version = "4.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "80d0e48e026ce7df2040239117d25e4e79714907420c70294a5ce4b6bbe6a7b6"
+dependencies = [
+ "clap",
+ "clap_complete",
+]
+
+[[package]]
name = "clap_derive"
version = "4.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2417,6 +2427,7 @@ dependencies = [
"chrono",
"clap",
"clap_complete",
+ "clap_complete_nushell",
"futures",
"itertools 0.10.5",
"mullvad-management-interface",
diff --git a/mullvad-cli/Cargo.toml b/mullvad-cli/Cargo.toml
index a489123847..0b32412c2d 100644
--- a/mullvad-cli/Cargo.toml
+++ b/mullvad-cli/Cargo.toml
@@ -32,8 +32,9 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread", "fs"] }
serde = { workspace = true }
serde_json = { workspace = true }
-[target.'cfg(all(unix, not(target_os = "android")))'.dependencies]
-clap_complete = { version = "4.4.8" }
+# [target.'cfg(all(unix, not(target_os = "android")))'.dependencies]
+clap_complete = { version = "4.5.2" }
+clap_complete_nushell = "4.5.1"
[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
diff --git a/mullvad-cli/src/main.rs b/mullvad-cli/src/main.rs
index 67990bd888..495fd0d21b 100644
--- a/mullvad-cli/src/main.rs
+++ b/mullvad-cli/src/main.rs
@@ -1,8 +1,13 @@
+#![deny(rust_2018_idioms)]
+
+// #[cfg(all(unix, not(target_os = "android")))]
use anyhow::Result;
use clap::Parser;
mod cmds;
mod format;
+use clap_complete_nushell::Nushell;
+
use cmds::*;
pub const BIN_NAME: &str = env!("CARGO_BIN_NAME");
@@ -117,7 +122,7 @@ enum Cli {
Version,
/// Generate completion scripts for the specified shell
- #[cfg(all(unix, not(target_os = "android")))]
+ // #[cfg(all(unix, not(target_os = "android")))]
#[command(hide = true)]
ShellCompletions {
/// The shell to generate the script for
@@ -176,15 +181,20 @@ async fn main() -> Result<()> {
Cli::ImportSettings { file } => patch::import(file).await,
Cli::ExportSettings { file } => patch::export(file).await,
- #[cfg(all(unix, not(target_os = "android")))]
- Cli::ShellCompletions { shell, dir } => {
- use anyhow::Context;
+ // #[cfg(all(unix, not(target_os = "android")))]
+ Cli::ShellCompletions { shell: _, dir } => {
use clap::CommandFactory;
// FIXME: The shell completions include hidden commands (including "shell-completions")
println!("Generating shell completions to {}", dir.display());
- clap_complete::generate_to(shell, &mut Cli::command(), BIN_NAME, dir)
- .context("Failed to generate shell completions")?;
+ // clap_complete::generate_to(shell, &mut Cli::command(), BIN_NAME, dir)
+ // .map_err(|_| anyhow!("Failed to generate shell completions"))?;
+ clap_complete::generate(
+ Nushell,
+ &mut Cli::command(),
+ BIN_NAME,
+ &mut std::io::stdout(),
+ );
Ok(())
}
}