Clap.Net
0.1.26-beta
See the version list below for details.
dotnet add package Clap.Net --version 0.1.26-beta
NuGet\Install-Package Clap.Net -Version 0.1.26-beta
<PackageReference Include="Clap.Net" Version="0.1.26-beta" />
<PackageVersion Include="Clap.Net" Version="0.1.26-beta" />
<PackageReference Include="Clap.Net" />
paket add Clap.Net --version 0.1.26-beta
#r "nuget: Clap.Net, 0.1.26-beta"
#:package Clap.Net@0.1.26-beta
#addin nuget:?package=Clap.Net&version=0.1.26-beta&prerelease
#tool nuget:?package=Clap.Net&version=0.1.26-beta&prerelease
Clap.Net
Clap.Net is an attempt to port clap-rs over to .NET, with almost feature-parity, to make source generated parsers for applications.
Installation
dotnet add package Clap.Net
Notes to the user
If you are having issues with generation and want to see what's going on, sometimes it's not enough to rely on the in-editor generated file, add this to your project to see the MSBuild-generated files.
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>bin/Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
Usage
Define your command-line interface using classes and properties. Use attributes to specify the command-line options and arguments.
using Clap.Net;
namespace Clap.Examples;
[Command(Name = "image-converter", Summary = "My app is pretty cool!")]
public partial class ImageConverter
{
[Arg(Description = "The path of the image to convert")]
public required string Path { get; init; }
[Arg(Description = "The destination path of the converted image (default: <file-name>.[new-ext])", Last = true)]
public string? DestinationPath { get; init; }
[Arg(ShortName = 'e', LongName = "extension")]
public string? Extension { get; init; }
[Arg(ShortName = 'v', LongName= "verbose")]
public bool Verbose { get; set; }
[Command(SubCommand = true)]
public ImageConverterCommands? Command { get; init; }
}
[SubCommand]
public partial class ImageConverterCommands
{
[Command]
public partial class History : ImageConverterCommands;
[Command]
public partial class Publish : ImageConverterCommands
{
[Arg(Description = "The url to publish the new image to")]
public required string[] UploadUrl { get; init; }
}
}
Parse the command-line arguments using the Parser class.
using System;
using Clap.Examples;
var app = ImageConverter.Parse(args);
switch (app.Command)
{
case ImageConverterCommands.History history:
// do something with history
break;
case ImageConverterCommands.Publish publish:
// do something with publish
break;
default:
// do something with app
break;
}
Run the application with command-line arguments.
dotnet run -- -v "~/Downloads/tree.png" "~/Downloads/tree.jpg"
dotnet run -- "~/Downloads/tree.png" -e "jpg" publish "https://yourdomain.com/upload"
Features
- Strongly-typed: Define your command-line interface using classes and properties.
- Subcommands: Define subcommands using nested classes.
- Options and Arguments: Define options and arguments using attributes.
- Automatic help generation: Generate help messages automatically.
Core Feature Parity
- [Command] support
- Define the root command type
- Support for Name, Description, Version
- [Subcommand] support
- Nesting subcommands as classes
- Subcommand help messages
- [Option] (named arguments)
- Short and long flags (e.g., -v, --verbose)
- Aliases for options
- Environment variable fallback
- Default values (handled by language)
- Required vs optional
- Action (Set, Append, Count, etc.)
- [Switch] (bool flags)
- Basic presence/absence flag
- Default to false unless specified
- Negatable flags (--no-flag)
- [Positional] arguments
- Order-based argument mapping
- Optional vs Required
- Default values (handled by language)
- Multiple values (e.g., list)
- Custom parsers
- TryParse support for complex types
- Validation attributes
- Help and version handling
- Automatic --help
- Automatic --version
- Custom help text
Contributing
There is still loads to do, pull-requests are welcome
License
MIT
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. 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.0
- OneOf (>= 3.0.271)
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 |
|---|---|---|
| 0.2.39 | 670 | 2/20/2026 |
| 0.2.38 | 130 | 2/19/2026 |
| 0.2.37 | 120 | 2/16/2026 |
| 0.2.36 | 131 | 2/11/2026 |
| 0.1.35-beta | 117 | 2/11/2026 |
| 0.1.34-beta | 117 | 2/11/2026 |
| 0.1.33-beta | 119 | 2/11/2026 |
| 0.1.32-beta | 504 | 1/17/2026 |
| 0.1.31-beta | 155 | 12/29/2025 |
| 0.1.30-beta | 263 | 10/30/2025 |
| 0.1.29-beta | 553 | 9/17/2025 |
| 0.1.28-beta | 368 | 9/16/2025 |
| 0.1.27-beta | 603 | 9/2/2025 |
| 0.1.26-beta | 266 | 8/29/2025 |
| 0.1.24-beta | 273 | 8/27/2025 |
| 0.1.23-beta | 274 | 8/27/2025 |
| 0.1.22-beta | 301 | 8/7/2025 |
| 0.1.21-beta | 295 | 8/6/2025 |
| 0.1.20-beta | 307 | 8/6/2025 |
| 0.1.19-beta | 302 | 8/6/2025 |