004: Nushell Integration¶
- Status: Developed
- Date: 2026-12-02
- Author(s): João V. Farias
- Traces to: ADR-006 Category 8 and ADR-010
Context¶
Static clap_complete scripts complete fixed command flags, yet they cannot query dynamic tasks, targets, variables, or managed prefixes from winesmith.toml. They also reject arbitrary Windows /flag switches on winesmith exec and positional KEY=VALUE variables on winesmith run inside Nushell. Nushell 0.117+ provides extern --strict, @structured, def --wrapped, and $nu.user-autoload-dirs to support parse-time checking, structured pipelines, and dynamic project completion together.
Benchmark¶
Generic clap_complete_nushell outputs lack @structured JSON decoding, def --wrapped flag passthrough, and local project completers. Writing native winesmith externs and wrappers keeps interactive terminal output readable while letting piped commands (winesmith env list | where windows == "win7") work on Nushell tables directly.
Interaction flow¶
Autoload setup, typed parsing, structured piping, and dynamic tab completion operate across four steps:
- Run
winesmith completions install nuonce to write$XDG_CONFIG_HOME/nushell/autoload/winesmith.nu(default~/.config/nushell/autoload/winesmith.nu, or--path <FILE>). - Restart Nushell or source the file so fixed subcommands (
init,setup,shell,doctor,env *,runner *,config,tasks,completions) validate flags at parse time viaextern --strict. - Pipe any of the seven query commands (
doctor,env list,env inspect,runner list,runner detect,config,tasks) directly into Nushell filters. The@structured [--json] { from json }attribute injects--jsonand parsesstdoutinto a table or record automatically. - Use
def --wrappedonwinesmith runandwinesmith execso Windows/flags,--operands, andKEY=VALUEarguments forward untouched to^winesmith, while pressingTABcalls hiddenwinesmith __complete <kind>.
Visual design¶
This diagram shows how commands typed inside Nushell route through strict externs, @structured auto-decoding, wrapped passthroughs, and local __complete lookups:
flowchart LR
Nu["Nushell 0.117+ Session"] -->|autoload| Script["~/.config/nushell/autoload/winesmith.nu"]
Script -->|Fixed subcommands| Strict["extern --strict"]
Script -->|Query subcommands| Struct["extern --strict + @structured [--json]"]
Script -->|exec & run| Wrapped["def --wrapped (...$rest)"]
Script -->|TAB completion| Hidden["^winesmith __complete <kind>"]
Hidden --> Local["Local winesmith.toml & XDG stores (<50ms)"]
Struct -->|Piped| Table["Native Nushell Table / Record"]
Struct -->|Terminal| Text["Human-Readable Table"]
Implementation¶
Command signature and style rules¶
Every winesmith CLI flag and every command, extern, and completer emitted by winesmith completions nu MUST obey five rules:
- Declare explicit
input -> outputtypes on everydefandextern. Writenothingwhen no value is consumed or returned, write the concrete output type (table,record,list<string>,string), and writeanyonly when unknowable. - Put each positional parameter and flag on its own line with its type after
:and an inline#comment explaining its purpose without repeating the parameter name. - Declare long two-dash flags exclusively (
--all-targets,--force,--target,--verbose,--quiet,--help) and forbid single-dash short flags (-t,-v,-q,-D,-h) across both the Rust CLI and generated Nushell definitions. - Use clear, consistent nouns and phrases across every command (
directoryrather thandir,manifest file to readrather thansource). - Place one space between the argument and
#, start comments with a capital letter, end every comment with a period, keep comments on one line, and appendDefault: <value>.when a default exists.
Generated Nushell excerpt¶
Below is a representative slice of the script emitted by winesmith completions nu (src/completions/mod.rs):
# Return project task names and descriptions for tab completion.
def "nu-complete winesmith tasks" []: nothing -> table {
^winesmith __complete tasks | complete | if $in.exit_code == 0 { $in.stdout | from json } else { [] }
}
# Return project target profile names for tab completion.
def "nu-complete winesmith targets" []: nothing -> table {
^winesmith __complete targets | complete | if $in.exit_code == 0 { $in.stdout | from json } else { [] }
}
# List all managed Wine prefix directories.
@structured [--json] { from json }
extern --strict "winesmith env list" [
--manifest-path: path # Manifest file to read. Default: nearest winesmith.toml.
--json # Emit structured JSON output. Default: false.
--verbose # Print detailed diagnostic logs to stderr. Default: false.
--quiet # Suppress non-essential status messages. Default: false.
--help # Show help information. Default: false.
]: nothing -> table
# Provision the runner, prefix directory, mounts, symlinks, toolchains, and lockfile.
extern --strict "winesmith setup" [
--manifest-path: path # Manifest file to read. Default: nearest winesmith.toml.
--target: string@"nu-complete winesmith targets" # Target profile to provision.
--all-targets # Provision every declared target profile. Default: false.
--locked # Fail when winesmith.lock is missing or outdated. Default: false.
--reinstall # Rebuild prefix settings and reinstall toolchains. Default: false.
--verbose # Print detailed diagnostic logs to stderr. Default: false.
--quiet # Suppress non-essential status messages. Default: false.
--help # Show help information. Default: false.
]: nothing -> nothing
# Run a declared Wine or Linux host task from the project manifest.
def --wrapped "winesmith run" [
task?: string@"nu-complete winesmith tasks" # Task name declared in winesmith.toml.
--manifest-path: path # Manifest file to read. Default: nearest winesmith.toml.
--target: string@"nu-complete winesmith targets" # Target profile to execute.
--all-targets # Execute the task across every declared target profile. Default: false.
--locked # Fail when winesmith.lock is missing or outdated. Default: false.
...rest: string@"nu-complete winesmith task-vars" # Variable overrides in key=value form and extra flags.
]: nothing -> nothing {
mut args = []
if $manifest_path != null { $args = ($args | append ["--manifest-path" $manifest_path]) }
if $target != null { $args = ($args | append ["--target" $target]) }
if $all_targets { $args = ($args | append "--all-targets") }
if $locked { $args = ($args | append "--locked") }
if $task != null { $args = ($args | append $task) }
^winesmith run ...$args ...$rest
}
Dynamic completion provider¶
winesmith __complete <kind> reads only local manifests and XDG state directories without network requests or Wine launches across six categories:
taskslists declared task names and descriptions from the nearestwinesmith.toml.task-varslists[vars]keys formatted as<key>=with their default value indescription.targetslists[targets.*]names alongside each target's resolved Windows version and architecture.envslists managed prefix directories found under$XDG_DATA_HOME/winesmith/prefixes/.runnerslists installed portable runners, detected system Wine and Proton installations, and the default Kron4ek tag.toolchainslists built-in ad-hoc recipe prefixes (dotnet@,python@,inno@,nsis@).
Edge cases and constraints¶
Automated tests enforce three invariants on the generated script and completion subcommand:
- Invoking
winesmith __completeoutside a project directory MUST exit0and emit[]with emptystderr. - Integration tests run
source <generated_file>directly inside hostnuwhenever available and check@structuredpiping plusextern --strictrejection of short flags. - Callers can bypass wrappers and
@structureddecoding at any time with^winesmith ....