Skip to content

.NET library for parsing command-line arguments.

License

Notifications You must be signed in to change notification settings

rednir/CliOptions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CliOptions

A simple and easy to use .NET library for parsing arguments in a command-line application.

Usage

Download from NuGet: dotnet add package CliOptions

Code example:

using System;
using CliOptions;

public static class Program
{
    private Options _options = new();

    public static void Main(string[] args)
    {
        _options.Parse(args);
        Console.WriteLine("Verbose mode is set to: " + myOptions.IsVerboseOn);
    }
}

public class Options : ArgumentsParser
{
    [PropertyOption("verbose", 'v', "Sets whether to be verbose.")]
    public bool IsVerboseOn { get; set; } = false;

    [MethodOption("help", 'h', "Displays all available options.")]
    public void Help()
    {
        Console.WriteLine("Application options:\n" + this.HelpText);

        // Application options:
        //    -v, --verbose [BOOLEAN]               Sets whether to be verbose.
        //    -h, --help                            Displays all available options.
        //    --output-text [STRING] [INT32]        Output some text.
    }

    [MethodOption("output-text", description: "Output some text.")]
    public void OutputText(string textToOutput, int numberOfTimes)
    {
        for (int i = 0; i < numberOfTimes; i++)
            Console.WriteLine(textToOutput);
    }
}

About

.NET library for parsing command-line arguments.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages