KingpinNet 1.0.224-alpha
See the version list below for details.
dotnet add package KingpinNet --version 1.0.224-alpha
NuGet\Install-Package KingpinNet -Version 1.0.224-alpha
<PackageReference Include="KingpinNet" Version="1.0.224-alpha" />
paket add KingpinNet --version 1.0.224-alpha
#r "nuget: KingpinNet, 1.0.224-alpha"
// Install KingpinNet as a Cake Addin #addin nuget:?package=KingpinNet&version=1.0.224-alpha&prerelease // Install KingpinNet as a Cake Tool #tool nuget:?package=KingpinNet&version=1.0.224-alpha&prerelease
Kingpin.Net style command line arguments parser and command line UI goodies for .NET
Overview
Kingpin.Net is a free interpretation of the glorious Kingpin golang project, found here.
Using coding fluent style, you can easily build a consistent commandline interface for your tool. Kingpin.Net supports type safety on arguments and flags, and supports nested commands.
Install the Kingpin.Net nuget package using the following command in the package manager console window
PM> Install-Package KingpinNet
The Nuget package can be found here
Features
- Fluent style API
- Rich support for commmands, sub-commands, arguments and flags
- Deep integration into Microsoft.Extensions.Configuration
- Type safe arguments and flags
- Beautiful console help
- POSIX Style short flags
- Customizable console help using the awesome Liquid syntax
- Context sensitive help output
- TAB Auto-completion on ZSH, Bash and Powershell
Usage
Here is the two major ways to add rich support for command line aruments into your application
Bare-bone example
In order just to get the simplest command line parsing up and running
class Program
{
static void Main(string[] args)
{
Kingpin.Version("0.0.1");
Kingpin.Author("Joe Malone");
Kingpin.ExitOnHelp();
Kingpin.ShowHelpOnParsingErrors();
FlagItem debug = Kingpin.Flag("debug", "Enable debug mode.").IsBool();
FlagItem timeout = Kingpin.Flag("timeout", "Timeout waiting for ping.")
.IsRequired().Short('t').IsDuration();
ArgumentItem ip = Kingpin.Argument("ip", "IP address to ping.").IsRequired().IsIp();
ArgumentItem count = Kingpin.Argument("count", "Number of packets to send").IsInt();
var result = Kingpin.Parse(args);
Console.WriteLine($"Would ping: {ip} with timeout {timeout} and count {count} with debug = {debug}");
Console.ReadLine();
}
}
Example integrating into Microsoft.Extensions.Configuration
Integrating with the configuration system build into .NET Core is equally easy. Just add .AddKingpinNetCommandLine(args) to your configuration builder
class Program
{
static void Main(string[] args)
{
Kingpin.Version("1.0").Author("Peter Andersen").ApplicationName("curl")
.ApplicationHelp("An example implementation of curl.");
Kingpin.ShowHelpOnParsingErrors();
var get = Kingpin.Command("get", "GET a resource.").IsDefault();
get.Argument("url", "Retrieve a URL.").IsDefault();
var post = Kingpin.Command("post", "POST a resource.");
post.Argument("url", "URL to POST to.").IsRequired().IsUrl();
var configuration = new ConfigurationBuilder().AddEnvironmentVariables()
.AddKingpinNetCommandLine(args).Build();
switch (configuration["command"])
{
case "get:url":
Console.WriteLine($"Getting URL {configuration["get:url"]}");
break;
case "post":
Console.WriteLine($"Posting to URL {configuration["post:url"]}");
break;
}
Console.ReadLine();
}
}
Auto-completion in Powershell, Bash and ZSH
KingpinNet supports auto completion on all the three major terminals. Just run the following commands with your tool:
For ZSH:
eval "$({Your-tool-executable} --suggestion-script-zsh)"
For Bash:
eval "$({Your-tool-executable} --suggestion-script-bash)"
For Powershell:
iex "$({Your-tool-executable} --suggestion-script-pwsh)"
After you run the script, you are able to have TAB auto complete on your tool.
Changelog
- 1.0
- Removed TT templates help generation
- Added default DotLiquid help template
- Cleaned up IConsole usage
- 0.9
- Added auto completion scripts for ZSH, Bash and Powershell
- 0.8
- Added first attempt on auto completions for PowerShell, BASH and ZSH
- 0.7
- Added KingpinNet.UI
- Added ProgressBar and Spinner widgets
- Removed all references to Microsofts static Console object and used the mockable IConsole interface instead
- Updated tests
- 0.6
- Bug fixes
- 0.5
- Bug fixes
- 0.4
- Added parse method to the KingpinApplication class
- 0.2
- Added support for Linux newlines
- Added documentation
- Refactored the help flag code
- 0.1
- Initial project structure setup
- Help on nested commands
- Added example applications
- Added template help using T4 templates
Reference documentation (WIP)
General configuration
Commands
Flags
Arguments
Custom help
Integration into .NET Core Options and Configuration
Mentions
- Check out this fantastic ASCII font library https://github.com/drewnoakes/figgle
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- DotLiquid (>= 2.2.548)
- Microsoft.CSharp (>= 4.7.0)
- Microsoft.Extensions.Configuration (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.16 | 202 | 9/14/2024 |
1.1.15 | 175 | 8/27/2024 |
1.1.14 | 82 | 8/27/2024 |
1.1.13 | 146 | 8/24/2024 |
1.1.12 | 121 | 8/18/2024 |
1.1.11 | 111 | 8/18/2024 |
1.1.9 | 1,134 | 5/2/2024 |
1.1.8 | 79 | 5/2/2024 |
1.1.7 | 96 | 5/1/2024 |
1.1.6 | 99 | 5/1/2024 |
1.1.5-alpha | 91 | 5/1/2024 |
1.0.230-alpha | 5,709 | 2/19/2022 |
1.0.227-alpha | 182 | 2/9/2022 |
1.0.224-alpha | 186 | 12/30/2021 |
1.0.222-alpha | 175 | 12/29/2021 |
1.0.218-alpha | 848 | 11/4/2021 |
1.0.216-alpha | 617 | 11/4/2021 |
1.0.214-alpha | 252 | 11/4/2021 |
1.0.212-alpha | 260 | 11/4/2021 |
0.9.203 | 1,616 | 7/1/2020 |
0.9.201 | 430 | 7/1/2020 |
0.9.199 | 591 | 6/6/2020 |
0.9.197 | 452 | 6/5/2020 |
0.9.195 | 461 | 6/5/2020 |
0.8.192 | 502 | 6/1/2020 |
0.8.190 | 501 | 5/31/2020 |
0.7.187 | 564 | 5/30/2020 |
0.7.177 | 548 | 5/29/2020 |
0.7.175 | 539 | 5/29/2020 |
0.7.173 | 463 | 5/29/2020 |
0.7.171 | 460 | 5/29/2020 |
0.7.169 | 449 | 5/29/2020 |
0.6.166 | 688 | 4/6/2020 |
0.6.164 | 562 | 4/5/2020 |
0.6.162 | 560 | 2/5/2020 |
0.5.154 | 608 | 11/16/2019 |
0.5.152 | 498 | 11/16/2019 |
0.4.150 | 492 | 11/16/2019 |
0.4.147 | 520 | 9/8/2019 |
0.4.145 | 524 | 9/8/2019 |
0.3.143 | 520 | 9/8/2019 |
0.3.140 | 534 | 9/8/2019 |
0.2.130 | 595 | 8/4/2019 |
0.2.125 | 588 | 6/11/2019 |
0.2.119 | 638 | 5/16/2019 |
0.2.117 | 592 | 5/16/2019 |
0.2.115 | 592 | 5/16/2019 |
0.2.109 | 588 | 5/16/2019 |
0.2.107 | 575 | 5/16/2019 |
0.2.105 | 611 | 5/16/2019 |
0.2.103 | 581 | 5/15/2019 |
0.2.99 | 593 | 5/15/2019 |
0.2.95 | 616 | 5/12/2019 |
0.2.91 | 600 | 5/11/2019 |
0.2.88 | 592 | 5/8/2019 |
0.1.85 | 615 | 5/8/2019 |
0.1.83 | 587 | 5/8/2019 |
0.1.76 | 628 | 4/27/2019 |
0.1.71 | 634 | 4/25/2019 |
0.1.69 | 631 | 4/25/2019 |
0.1.66 | 661 | 4/7/2019 |
0.1.61 | 607 | 4/5/2019 |
0.1.59 | 599 | 4/5/2019 |
0.1.34 | 630 | 4/5/2019 |
0.1.33 | 622 | 4/5/2019 |
0.1.32 | 580 | 4/5/2019 |
0.1.31 | 593 | 4/5/2019 |
0.1.30 | 633 | 4/5/2019 |