DigitalZenWorks.CommandLine.Commands
1.5.23
dotnet add package DigitalZenWorks.CommandLine.Commands --version 1.5.23
NuGet\Install-Package DigitalZenWorks.CommandLine.Commands -Version 1.5.23
<PackageReference Include="DigitalZenWorks.CommandLine.Commands" Version="1.5.23" />
<PackageVersion Include="DigitalZenWorks.CommandLine.Commands" Version="1.5.23" />
<PackageReference Include="DigitalZenWorks.CommandLine.Commands" />
paket add DigitalZenWorks.CommandLine.Commands --version 1.5.23
#r "nuget: DigitalZenWorks.CommandLine.Commands, 1.5.23"
#:package DigitalZenWorks.CommandLine.Commands@1.5.23
#addin nuget:?package=DigitalZenWorks.CommandLine.Commands&version=1.5.23
#tool nuget:?package=DigitalZenWorks.CommandLine.Commands&version=1.5.23
DigitalZenWorks.CommandLine.Commands
A lightweight C# library for named commands, short and long options, option values, positional arguments, JSON command definitions, and help output. The application retains control of command execution.
Installation
Add the package to your application:
dotnet add package DigitalZenWorks.CommandLine.Commands
Or use Visual Studio's Package Manager Console:
Install-Package DigitalZenWorks.CommandLine.Commands
Quick start
In a console application, define the accepted commands and options, then validate the supplied arguments:
using System;
using System.Collections.Generic;
using DigitalZenWorks.CommandLine.Commands;
Command help = new("help");
help.Description = "Show available commands";
CommandOption encoding = new("e", "encoding", true);
CommandOption dryRun = new("n", "dryrun");
List<CommandOption> options = new();
options.Add(encoding);
options.Add(dryRun);
Command convert = new("convert", options, 1, "Convert a data file");
List<Command> commands = new();
commands.Add(help);
commands.Add(convert);
CommandLineInstance commandLine = new(commands, args);
if (commandLine.ValidArguments == false)
{
Console.Error.WriteLine(commandLine.ErrorMessage);
commandLine.ShowHelp();
return;
}
Command command = commandLine.Command;
if (command.Name == "help")
{
commandLine.ShowHelp();
return;
}
string inputPath = command.Parameters[0];
CommandOption encodingOption = command.GetOption("e", "encoding");
string encodingName = "utf-8";
if (encodingOption != null)
{
encodingName = encodingOption.Parameter;
}
bool dryRunRequested = command.DoesOptionExist("n", "dryrun");
Console.WriteLine("Input: " + inputPath);
Console.WriteLine("Encoding: " + encodingName);
Console.WriteLine("Dry run: " + dryRunRequested);
Example invocations:
dotnet run -- convert --encoding utf-8 --dryrun input.txt
dotnet run -- convert -e utf-8 -n input.txt
dotnet run -- help
The 1 in the Command constructor is the minimum number of positional
arguments. Setting requiresParameter to true on a CommandOption makes
it consume the following argument as its value. Supply values separately,
as in --encoding utf-8.
JSON command definitions
Commands can also be defined in a JSON file, such as commands.json:
[
{
"command": "help",
"description": "Show available commands"
},
{
"command": "convert",
"description": "Convert a data file",
"parameterCount": 1,
"options":
[
{
"shortName": "e",
"longName": "encoding",
"requiresParameter": true
},
{
"shortName": "n",
"longName": "dryrun",
"requiresParameter": false
}
]
}
]
Load the definitions instead of constructing the command list in code:
using System.IO;
using DigitalZenWorks.CommandLine.Commands;
string jsonText = File.ReadAllText("commands.json");
CommandsSet commandSet = new(jsonText);
CommandLineInstance commandLine = new(commandSet, args);
Check ValidArguments before accessing the selected command, its options,
or its positional arguments. See the XML documentation in the
library source for individual API contracts.
Target frameworks
The current Release configuration targets .NET Standard 2.0, .NET Framework 4.7.2, and .NET 5, 6, 7, 8, 9, and 10. Debug builds target .NET 10 only. See the package page for a published version's frameworks and its dependencies.
Build and test
Install the .NET 10 SDK, then clone and build the repository:
git clone https://github.com/jamesjohnmcguire/CommandLineCommands.git
cd CommandLineCommands
dotnet build CommandLineCommands.slnx --configuration Debug
dotnet test CommandLineCommands.slnx --configuration Debug
See the development notes for Release builds,
versioning, trusted publishing, and the build.cmd helper.
Contributing
Report bugs and propose improvements through GitHub issues.
For a pull request:
- Fork the Project
- Create your focused branch
- Add your code changes
- Add or update tests to validate your changes
- Commit and Push your Changes
- Open a Pull Request. Include the description of the change, its validation, and any related issue in the PR.
Coding style
Please match the current coding style. Most notably:
- One operation per line
- Use complete, self-documenting English words in variable and method names
- Attempt to declare variable and method names in a self-documenting manner
- Use tabs and Allman braces
Keep public API compatibility in mind: this library is consumed as NuGet package.
License
Distributed under the MIT License.
Contact
James John McGuire — jamesjohnmcguire@gmail.com
Project repository. If the library is useful to you, consider giving it a star.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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 is compatible. 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 is compatible. 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 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. |
| .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 is compatible. 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. |
-
.NETFramework 4.7.2
- Common.Logging (>= 3.4.1)
- Common.Logging.Core (>= 3.4.1)
- NewtonSoft.Json (>= 13.0.4)
-
.NETStandard 2.0
- Common.Logging (>= 3.4.1)
- Common.Logging.Core (>= 3.4.1)
- NewtonSoft.Json (>= 13.0.4)
-
net10.0
- Common.Logging (>= 3.4.1)
- Common.Logging.Core (>= 3.4.1)
- NewtonSoft.Json (>= 13.0.4)
-
net5.0
- Common.Logging (>= 3.4.1)
- Common.Logging.Core (>= 3.4.1)
- NewtonSoft.Json (>= 13.0.4)
-
net6.0
- Common.Logging (>= 3.4.1)
- Common.Logging.Core (>= 3.4.1)
- NewtonSoft.Json (>= 13.0.4)
-
net7.0
- Common.Logging (>= 3.4.1)
- Common.Logging.Core (>= 3.4.1)
- NewtonSoft.Json (>= 13.0.4)
-
net8.0
- Common.Logging (>= 3.4.1)
- Common.Logging.Core (>= 3.4.1)
- NewtonSoft.Json (>= 13.0.4)
-
net9.0
- Common.Logging (>= 3.4.1)
- Common.Logging.Core (>= 3.4.1)
- NewtonSoft.Json (>= 13.0.4)
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.5.23 | 39 | 11/5/2026 |
| 1.5.22 | 265 | 6/29/2026 |
| 1.5.18 | 388 | 10/28/2025 |
| 1.5.16 | 277 | 10/27/2025 |
| 1.5.14 | 276 | 10/22/2025 |
| 1.4.12 | 351 | 3/22/2025 |
| 1.4.11 | 364 | 3/10/2025 |
| 1.3.10 | 271 | 1/12/2025 |
| 1.2.8 | 301 | 8/7/2024 |
| 1.1.6 | 314 | 4/9/2024 |
| 1.1.5 | 398 | 10/20/2023 |
| 1.1.4 | 261 | 9/10/2023 |
| 1.0.2 | 402 | 10/31/2022 |