Oaksoft.ArgumentParser 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Oaksoft.ArgumentParser --version 1.0.1                
NuGet\Install-Package Oaksoft.ArgumentParser -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="Oaksoft.ArgumentParser" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Oaksoft.ArgumentParser --version 1.0.1                
#r "nuget: Oaksoft.ArgumentParser, 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 Oaksoft.ArgumentParser as a Cake Addin
#addin nuget:?package=Oaksoft.ArgumentParser&version=1.0.1

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

NuGet NuGet

Command Line Arguments Parser Library for .Net

Oaksoft.ArgumentParser is a fluent and simple command line arguments parser library. It is currently in under development and this documentation is for version v1.0.0.

Quick Start Example

  1. Create a class to define your options.
  2. Register your options and build the parser.
using Oaksoft.ArgumentParser;
using Oaksoft.ArgumentParser.Extensions;
using Oaksoft.ArgumentParser.Parser;

namespace QuickStart;

internal class CalculatorOptions
{
    public double LeftOperand { get; set; }
    public double RightOperand { get; set; }
    public string? Operator { get; set; }
}

internal static class Program
{
    private static void Main(string[] args)
    {
        try
        {
            var parser = CommandLine.CreateParser<CalculatorOptions>()
                .AddNamedOption(p => p.LeftOperand)
                .AddNamedOption(p => p.RightOperand)
                .AddNamedOption(o => o.Operator)
                .Build();

            parser.Run(args, EvaluateOption);
        }
        catch (System.Exception ex)
        {
            System.Console.WriteLine(ex.Message);
        }
    }

    private static void EvaluateOption(IArgumentParser<CalculatorOptions> parser, CalculatorOptions option)
    {
        if (!parser.IsValid || string.IsNullOrWhiteSpace(option.Operator))
            return;

        var result = option.Operator.ToUpperInvariant() switch
        {
            "ADD" => $"{option.LeftOperand} + {option.RightOperand} = {option.LeftOperand + option.RightOperand}",
            "SUB" => $"{option.LeftOperand} - {option.RightOperand} = {option.LeftOperand - option.RightOperand}",
            "MUL" => $"{option.LeftOperand} * {option.RightOperand} = {option.LeftOperand * option.RightOperand}",
            "DIV" => $"{option.LeftOperand} / {option.RightOperand} = {option.LeftOperand / option.RightOperand}",
            _ => "Invalid argument!"
        };

        System.Console.WriteLine($"Result: {result}");
        System.Console.WriteLine();
    }
}

Sample Command line output for the above console application

Type the options and press enter. Type 'q' to quit.
./> -l 13 -r 8 -o MUL
Result: 13 * 8 = 104

Library Overview

This documentation shows how to create a .NET command-line app that uses the Oaksoft.ArgumentParser library. You'll begin by creating a simple option. Then you'll add to that base, creating a more complex app that contains multiple options.

In this documentation, you learn how to:

  • Create switch, counter, named and value options.
  • Specify default value for options.
  • Specify allowed values for options.
  • Create aliases for named options.
  • Work with string, string[], int, bool, double, ... option types.
  • Use custom code for parsing and validating options.
  • Configure option and value counts.
  • Configure sequential values.
  • Configure option usage and decription texts.

Soon, i will add detailed documentation and describe the topics above!

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

    • No dependencies.
  • 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.5.3 144 2/5/2024
1.5.2 110 2/1/2024
1.5.1 110 1/30/2024
1.5.0 90 1/27/2024
1.4.2 104 1/26/2024
1.4.1 100 1/25/2024
1.4.0 92 1/24/2024
1.3.0 113 1/22/2024
1.2.0 102 1/19/2024
1.1.0 118 1/18/2024 1.1.0 is deprecated because it is no longer maintained.
1.0.1 119 1/17/2024 1.0.1 is deprecated because it is no longer maintained.
1.0.0 114 1/12/2024 1.0.0 is deprecated because it is no longer maintained.