ArgSharpCLI
is a feature-rich, yet lightweight, command-line argument parser designed for C# applications. It's built with SOLID principles, making your CLI apps both easy to develop and maintain.
- 📦 Out-of-the-box functionality
- 🛠️ Easy command and sub-command registration
- 👁️ Support for short (
-h
) and long (--help
) option names - 📘 Built-in help features
- 🔌 Extensibility for complex scenarios
- 🌟 SOLID principles for high maintainability
dotnet add package ArgSharpCLI
The following example demonstrates adding a simple TestCommand class and executing it.
using ArgSharpCLI;
// Define a simple command
[Command(Name = "test")]
public class TestCommand : ICommand
{
[Option("test-option", "t", "test option")]
public string? TestOption { get; set; }
[Option("test-boolean-option", "b", "test boolean option")]
public bool TestBooleanOption { get; set; }
}
// In your Main method
var command = new CommandBuilder()
.AddArguments(args)
.AddCommand<TestCommand>()
.Build();
// Execute the built command
command.Match(
onSuccess: cmd => cmd.Run(),
onFailure: err => Console.WriteLine($"Error: {err}")
);
You can organize your commands into sub-commands as shown below:
using ArgSharpCLI;
// Define the main command
[Command(Name = "main")]
public class MainCommand : ICommand
{
// Implementation here
}
// Define a sub-command
[Command(Name = "sub")]
public class SubCommand : ICommand
{
// Implementation here
}
// In your Main method
var command = new CommandBuilder()
.AddArguments(args)
.AddCommand<MainCommand>(cmd => {
cmd.AddSubCommand<SubCommand>();
})
.Build();
// Execute the command
// Execute the built command
command.Match(
onSuccess: cmd => cmd.Run(),
onFailure: err => Console.WriteLine($"Error: {err}")
);
This project is licensed under the MIT License. Feel free to copy and paste this markdown into your README.md file, and adjust it as necessary to fit your project.