Skip to content

rmazza/ArgSharpCLI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArgSharpCLI

NuGet Build Status

Overview

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.

Table of Contents

Features

  • 📦 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

Getting Started

Installation

dotnet add package ArgSharpCLI

Basic Usage

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}")
);

Advanced Usage

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}")
);

License

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.

About

.NET CLI Parser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages