Skip to content

Commit dfccbfb

Browse files
committed
Document detectShell() API and private field compile warning
completers.md: - Added Shell Detection section with AeshRuntimeRunner.detectShell() API, usage example, and detection order documentation annotation-processor.md: - Note that the processor emits a compile-time warning for private fields suggesting package-private visibility (PR #547)
1 parent 81de637 commit dfccbfb

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

content/docs/aesh/annotation-processor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ For each option, argument, and mixin field, the generated code provides:
128128

129129
- **Public / package-private fields** -- The generated code uses direct field access (`((MyCommand) inst).myField = value`). No `java.lang.reflect.Field`, no `getDeclaredField()`, no `setAccessible()`. This is the fastest possible path and requires no GraalVM native-image reflection configuration.
130130

131-
- **Private fields** -- The generated code resolves `Field` constants once in a `static {}` initializer and caches them for reuse. This avoids repeated class hierarchy walks but still uses `getDeclaredField()` + `setAccessible()` at class load time, and requires reflection entries in native-image configuration (which the processor generates automatically -- see [GraalVM Native Image](#graalvm-native-image) below).
131+
- **Private fields** -- The generated code resolves `Field` constants once in a `static {}` initializer and caches them for reuse. This avoids repeated class hierarchy walks but still uses `getDeclaredField()` + `setAccessible()` at class load time, and requires reflection entries in native-image configuration (which the processor generates automatically -- see [GraalVM Native Image](#graalvm-native-image) below). The processor emits a **compile-time warning** for private fields suggesting package-private visibility.
132132

133133
## Generated Code
134134

content/docs/aesh/completers.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,26 @@ String fishScript = ShellCompletionGenerator.generateDynamic(
373373
ShellCompletionGenerator generator = ShellCompletionGenerator.forShell(ShellType.ZSH);
374374
String script = generator.generate(parser, "myapp");
375375
```
376+
377+
### Shell Detection
378+
379+
Use `AeshRuntimeRunner.detectShell()` to detect the current shell from environment variables. This is the same logic used by `--aesh-completion` and `--aesh-completion-install` for auto-detection.
380+
381+
```java
382+
import org.aesh.AeshRuntimeRunner;
383+
import org.aesh.util.completer.ShellCompletionGenerator.ShellType;
384+
385+
ShellType shell = AeshRuntimeRunner.detectShell();
386+
if (shell != null) {
387+
System.out.println("Current shell: " + shell);
388+
} else {
389+
System.out.println("Could not detect shell");
390+
}
391+
```
392+
393+
Detection order:
394+
1. `PSModulePath` — PowerShell (checked first to avoid misdetection from bash wrapper scripts)
395+
2. `FISH_VERSION` — Fish
396+
3. `ZSH_VERSION` — Zsh
397+
4. `BASH_VERSION` — Bash
398+
5. `$SHELL` fallback — checks the path for fish/zsh/bash/pwsh

0 commit comments

Comments
 (0)