Repository: clap-rs/clap (language: rust)

Issue:
Allow the generated nushell completion scripts to be used as module and overlay
### Please complete the following tasks

- [X] I have searched the [discussions](https://github.com/clap-rs/clap/discussions)
- [X] I have searched the [open](https://github.com/clap-rs/clap/issues) and [rejected](https://github.com/clap-rs/clap/issues?q=is%3Aissue+label%3AS-wont-fix+is%3Aclosed) issues

### Clap Version

master

### Describe your use case

The current nushell completion scripts generated by clap_complete_nushell can only be used as script with `source` command, I wish the generated scripts were more general and could be used as module and overlay.

### Describe the solution you'd like

Allow the nushell completion scripts to be used as module and overlay. For example:

* module
```
clap_complete_nushell/tests/snapshots on  nu
❯ use basic.nu *
clap_complete_nushell/tests/snapshots on  nu
❯ | my-app
my-app
my-app test       Subcommand
my-app help       Print this message or the help of the given subcommand(s)
my-app help help  Print this message or the help of the given subcommand(s)
my-app help test  Subcommand
```

* overlay
```
clap_complete_nushell/tests/snapshots on  nu
❯ overlay use basic.nu
clap_complete_nushell/tests/snapshots on  nu
❯ | my-app
my-app
my-app help       Print this message or the help of the given subcommand(s)
my-app test       Subcommand
my-app help test  Subcommand
my-app help help  Print this message or the help of the given subcommand(s)
```

### Alternatives, if applicable

_No response_

### Additional Context

_No response_


Discussion / hints:

Fix patch:
diff --git a/clap_complete_nushell/src/lib.rs b/clap_complete_nushell/src/lib.rs
index 3ec128878be..e686b7cf584 100644
--- a/clap_complete_nushell/src/lib.rs
+++ b/clap_complete_nushell/src/lib.rs
@@ -42,7 +42,7 @@ impl Generator for Nushell {
         }
 
         completions.push_str("}\n\n");
-        completions.push_str("use completions *\n");
+        completions.push_str("export use completions *\n");
 
         buf.write_all(completions.as_bytes())
             .expect("Failed to write to generated file")


Test patch:
diff --git a/clap_complete_nushell/tests/snapshots/aliases.nu b/clap_complete_nushell/tests/snapshots/aliases.nu
index 2c84770d329..8263e60315e 100644
--- a/clap_complete_nushell/tests/snapshots/aliases.nu
+++ b/clap_complete_nushell/tests/snapshots/aliases.nu
@@ -15,4 +15,4 @@ module completions {
 
 }
 
-use completions *
+export use completions *
diff --git a/clap_complete_nushell/tests/snapshots/basic.nu b/clap_complete_nushell/tests/snapshots/basic.nu
index b905e5aa591..f1d52b1fe7c 100644
--- a/clap_complete_nushell/tests/snapshots/basic.nu
+++ b/clap_complete_nushell/tests/snapshots/basic.nu
@@ -27,4 +27,4 @@ module completions {
 
 }
 
-use completions *
+export use completions *
diff --git a/clap_complete_nushell/tests/snapshots/feature_sample.nu b/clap_complete_nushell/tests/snapshots/feature_sample.nu
index 1676a10d26d..f98c5a2bb52 100644
--- a/clap_complete_nushell/tests/snapshots/feature_sample.nu
+++ b/clap_complete_nushell/tests/snapshots/feature_sample.nu
@@ -36,4 +36,4 @@ module completions {
 
 }
 
-use completions *
+export use completions *
diff --git a/clap_complete_nushell/tests/snapshots/home/test/nu/.config/nushell/completions/test.nu b/clap_complete_nushell/tests/snapshots/home/test/nu/.config/nushell/completions/test.nu
index b8e0d6d402b..03c5cd6bd1b 100644
--- a/clap_complete_nushell/tests/snapshots/home/test/nu/.config/nushell/completions/test.nu
+++ b/clap_complete_nushell/tests/snapshots/home/test/nu/.config/nushell/completions/test.nu
@@ -255,4 +255,4 @@ module completions {
 
 }
 
-use completions *
+export use completions *
diff --git a/clap_complete_nushell/tests/snapshots/quoting.nu b/clap_complete_nushell/tests/snapshots/quoting.nu
index 3c5e6ccc5a5..485d77d4cec 100644
--- a/clap_complete_nushell/tests/snapshots/quoting.nu
+++ b/clap_complete_nushell/tests/snapshots/quoting.nu
@@ -75,4 +75,4 @@ module completions {
 
 }
 
-use completions *
+export use completions *
diff --git a/clap_complete_nushell/tests/snapshots/special_commands.nu b/clap_complete_nushell/tests/snapshots/special_commands.nu
index 3111f51cdc3..fc01a39acba 100644
--- a/clap_complete_nushell/tests/snapshots/special_commands.nu
+++ b/clap_complete_nushell/tests/snapshots/special_commands.nu
@@ -64,4 +64,4 @@ module completions {
 
 }
 
-use completions *
+export use completions *
diff --git a/clap_complete_nushell/tests/snapshots/sub_subcommands.nu b/clap_complete_nushell/tests/snapshots/sub_subcommands.nu
index 607a9296dbd..c6e32a0b048 100644
--- a/clap_complete_nushell/tests/snapshots/sub_subcommands.nu
+++ b/clap_complete_nushell/tests/snapshots/sub_subcommands.nu
@@ -73,4 +73,4 @@ module completions {
 
 }
 
-use completions *
+export use completions *
diff --git a/clap_complete_nushell/tests/snapshots/value_hint.nu b/clap_complete_nushell/tests/snapshots/value_hint.nu
index 82a91ae80c6..2cc0b5ab800 100644
--- a/clap_complete_nushell/tests/snapshots/value_hint.nu
+++ b/clap_complete_nushell/tests/snapshots/value_hint.nu
@@ -24,4 +24,4 @@ module completions {
 
 }
 
-use completions *
+export use completions *