From 3cecb00938a2bc6cfdf001ddb066f7e83ea2570e Mon Sep 17 00:00:00 2001
From: Nicolas80 <nicolas.pmail@protonmail.com>
Date: Fri, 16 May 2025 15:39:14 +0200
Subject: [PATCH] gcli command auto completion and arm64 build

- Added detailed instructions for generating the completion script and registering it for your shell when calling `gcli completion --help`
- Added that information in the CHANGELOG.md
- Moved `indoc` crate dependency in Cargo.toml to make it explicit it's now also used outside of tests.
---
 CHANGELOG.md |  3 ++-
 Cargo.toml   |  2 +-
 src/main.rs  | 28 +++++++++++++++++++++++++++-
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 20c14a6..62d3993 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,9 +3,10 @@
 List of changelogs ordered from latest to oldest
 
 
-## [0.4.2] - 2025-05-12
+## [0.4.2] - 2025-05-16
 ### Added / Changed
 - Extra command `completion` added which takes a `--shell` argument to generate a completions script for a specified shell.
+  - Calling this command with `gcli completion --help` will provide detailed instructions to generate the completion script and register it for your shell (not necessary when using the `.deb` package that include and registers the completion scripts for `bash`, `zsh` and `fish`)
 
 ### CI/CD
 - Adapted the Linux (amd64) build to:
diff --git a/Cargo.toml b/Cargo.toml
index 1d1b0b5..2e952bc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -46,6 +46,7 @@ bs58 = "^0.5.1"
 directories = "^5.0.1"
 comfy-table = "^7.1.1"
 sea-orm = { version = "1.1.0", features = [ "sqlx-sqlite", "runtime-tokio-native-tls", "macros" ] }
+indoc = "2.0.5"
 
 # crypto
 scrypt = { version = "^0.11", default-features = false } # for old-style key generation
@@ -56,7 +57,6 @@ colored = "2.1.0"
 
 # Tests
 rstest = "0.23.0"
-indoc = "2.0.5"
 
 # allows to build gcli for different runtimes and with different predefined networks 
 [features]
diff --git a/src/main.rs b/src/main.rs
index 2a03562..8e417d6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -18,6 +18,7 @@ use codec::Encode;
 use colored::Colorize;
 use data::*;
 use display::DisplayEvent;
+use indoc::indoc;
 use keys::*;
 use runtime_config::*;
 use serde::{Deserialize, Serialize};
@@ -160,7 +161,32 @@ pub enum Subcommand {
 	/// Publish a new git tag with actual version
 	#[clap(hide = true)]
 	Publish,
-	/// Generate a completions script for a specified shell
+	/// Generate a completions script for a specified shell (use `completion --help` for more info)
+	#[clap(long_about = indoc! {r#"Generate a completions script for a specified shell.
+
+		The base completion scripts for `bash`, `zsh` or `fish` are already registered when installing the `.deb` package.
+		If you did not/could not install the `.deb` package we can generate the script and then configure the shell to use it.
+
+		Example for `bash`:
+		  mkdir -p ~/.local/share/gcli
+		  gcli completion --shell bash > ~/.local/share/gcli/completion.bash
+		  # Direct test - gcli should have the completion after the source command
+		  source ~/.local/share/gcli/completion.bash
+
+		  # Persisting the configuration in the shell configuration file, add this at the end of your `~/.bashrc` file
+		  [[ -f $HOME/.local/share/gcli/completion.bash ]] && source $HOME/.local/share/gcli/completion.bash
+		  # Might need to reopen the shell for the configuration to be applied
+
+		Example for `zsh`:
+		  mkdir -p ~/.local/share/gcli
+		  gcli completion --shell zsh > ~/.local/share/gcli/completion.zsh
+		  # Direct test - gcli should have the completion after the source command
+		  source ~/.local/share/gcli/completion.zsh
+
+		  # Persisting the configuration in the shell configuration file, add this at the end of your `~/.zshrc` file
+		  [[ -f $HOME/.local/share/gcli/completion.zsh ]] && source $HOME/.local/share/gcli/completion.zsh
+		  # Might need to reopen the shell for the configuration to be applied
+		"#})]
 	Completion {
 		/// target shell
 		#[clap(long)]
-- 
GitLab