Wolfe.CommandLine
0.2.0
dotnet add package Wolfe.CommandLine --version 0.2.0
NuGet\Install-Package Wolfe.CommandLine -Version 0.2.0
<PackageReference Include="Wolfe.CommandLine" Version="0.2.0" />
<PackageVersion Include="Wolfe.CommandLine" Version="0.2.0" />
<PackageReference Include="Wolfe.CommandLine" />
paket add Wolfe.CommandLine --version 0.2.0
#r "nuget: Wolfe.CommandLine, 0.2.0"
#:package Wolfe.CommandLine@0.2.0
#addin nuget:?package=Wolfe.CommandLine&version=0.2.0
#tool nuget:?package=Wolfe.CommandLine&version=0.2.0
Wolfe.CommandLine
Wolfe.CommandLine is a set of utility extensions for the System.CommandLine package, including automatic completion registration.
Installation
Installation is as easy as just adding the package:
dotnet package add Wolfe.CommandLine
Usage
Tab completion
System.CommandLine does support suggestions out of the box using dotnet suggest, but they're not wired up anywhere. Your shell needs to know they
exist and how to access them, so this utility package puts that wiring in place with a completion command group.
using System.CommandLine;
using Wolfe.CommandLine.Completions;
var root = new RootCommand()
.AddCompletions("my-app");
This registers:
- the 'suggest' directive that the completion scripts call back into
- a
completioncommand group:my-app completion <shell>— emit the script (bash, zsh, fish, pwsh)my-app completion install <shell>— install itmy-app completion uninstall <shell>— remove it
How install works
Installation will pick a directory that the shell loads completions from automatically, if one is available, so no startup file is edited:
- fish —
~/.config/fish/completions/(always) - bash — the XDG bash-completion user directory (when the bash-completion package is present)
- zsh — a writable
$fpathdirectory, preferring brew'ssite-functions(when it exists)
When no such directory is available (always for pwsh), it falls back to a managed
# >>> my-app completion >>> block in the shell's startup file. Uninstall sweeps both.
Auto-install
To skip the manual completion install step entirely, call the auto-installer once at startup,
before invoking the parsed command:
var root = new RootCommand()
.AddCompletions("my-app");
await CompletionAutoInstall.Run("my-app", args);
return await root.Parse(args).InvokeAsync();
The first time the app runs, completion is installed for the user's current shell:
- silently (with a notice on stderr) when there is a directory the shell loads automatically
- behind a
[y/N]prompt when it would have to edit a startup file
It runs at most once per shell, and never throws. It won't prompt unless the terminal is interactive, and if the user declines, their answer is recorded under the XDG state home.
The installed scripts are thin bridges: on tab they run my-app [suggest:<cursor>] "<line>" and feed the
candidates back to the shell, so completions always match the installed binary and never go stale.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- System.CommandLine (>= 2.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.