XenoAtom.CommandLine 1.0.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package XenoAtom.CommandLine --version 1.0.1
NuGet\Install-Package XenoAtom.CommandLine -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XenoAtom.CommandLine" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XenoAtom.CommandLine --version 1.0.1
#r "nuget: XenoAtom.CommandLine, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install XenoAtom.CommandLine as a Cake Addin
#addin nuget:?package=XenoAtom.CommandLine&version=1.0.1

// Install XenoAtom.CommandLine as a Cake Tool
#tool nuget:?package=XenoAtom.CommandLine&version=1.0.1

XenoAtom.CommandLine ci coverage NuGet

<img align="right" width="256px" height="256px" src="https://raw.githubusercontent.com/XenoAtom/XenoAtom.CommandLine/main/img/icon.png">

XenoAtom.CommandLine is a lightweight, powerful and NativeAOT friendly command line parser.

It is a fork of the excellent NDesk.Options/Mono.Options with several small improvements and new features.

โœจ Features

  • Lightweight library with no dependencies
  • net8.0+ ready and NativeAOT friendly, no System.Reflection used
  • Provides a simple API to parse command line arguments
  • Generates a help message from the command line definition
    • What you declare is what you get!
  • Supports
    • Commands and sub-command parsing (e.g. git commit -m "message")
    • Tar and POSIX style options (e.g. -abc is equivalent to -a -b -c)
    • -, / and -- option prefixes (e.g. -v, /v, --verbose))
    • Multiple option values (e.g. -i foo -i bar)
    • Optional and required option values : (e.g. -o[BAR] -oBAR)
    • Key/value pairs (e.g. `-DMACRO=VALUE1)
    • Option aliases (e.g. -v, -verbose)
    • -- to stop option parsing
    • --help and --version built-in options
    • Parsing of values to specific target types (e.g. int, bool, enum, etc.))
    • Response files e.g @file.txt
    • Grouping of command/options that can be activated together when a specific condition is met.

๐Ÿงช Example

using System;
using XenoAtom.CommandLine;

const string _ = "";
string? name = null;
int age = 0;
List<string> messages = new List<string>();

var commandApp = new CommandApp("myexe")
{
    _,
    {"n|name=", "Your {NAME}", v => name = v},
    {"a|age=", "Your {AGE}", (int v) => age = v},
    new HelpOption(),
    _,
    "Available commands:",
    new Command("commit")
    {
        _,
        {"m|message=", "Add a {MESSAGE} to this commit", messages},
        new HelpOption(),

        // Action for the commit command
        (arguments) =>
        {
            Console.Out.WriteLine($"Committing with name={name}, age={age}");
            foreach (var message in messages)
            {
                Console.Out.WriteLine($"Commit message: {message}");
            }
            return ValueTask.FromResult(0);
        }
    },
    // Default action if no command is specified
    (_) =>
    {
        Console.Out.WriteLine($"Hello {name}! You are {age} years old.");
        return ValueTask.FromResult(0);
    }
};

await commandApp.RunAsync(args);

Running myexe --help will output:

Usage: myexe [Options] COMMAND

  -n, --name=NAME            Your NAME
  -a, --age=AGE              Your AGE
  -h, -?, --help             Show this message and exit

Available commands:
  commit    

Running myexe --name John -a50 will output:

Hello John! You are 50 years old.

Running myexe commit --help will output:

Usage: myexe commit [Options]

  -m, --message=MESSAGE      Add a MESSAGE to this commit
  -h, -?, --help             Show this message and exit

Running myexe --name John -a50 commit --message "Hello!" --message "World!" will output:

Committing with name=John, age=50
Commit message: Hello!
Commit message: World!

๐Ÿ“ƒ User Guide

For more details on how to use XenoAtom.CommandLine, please visit the user guide.

๐Ÿ—๏ธ Build

You need to install the .NET 8 SDK. Then from the root folder:

$ dotnet build src -c Release

๐Ÿชช License

This software is released under the BSD-2-Clause license.

The license also integrate the original MIT license from Mono.Options.

๐Ÿค— Author

Alexandre Mutel aka xoofx.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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.0.1 236 5/6/2024
1.0.0 267 5/4/2024