Easy.CommandLine 1.0.0

dotnet add package Easy.CommandLine --version 1.0.0                
NuGet\Install-Package Easy.CommandLine -Version 1.0.0                
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="Easy.CommandLine" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Easy.CommandLine --version 1.0.0                
#r "nuget: Easy.CommandLine, 1.0.0"                
#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 Easy.CommandLine as a Cake Addin
#addin nuget:?package=Easy.CommandLine&version=1.0.0

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

Easy.CommandLine

Easy.CommandLine is an open-source and cross-platform package that can help us to define and parse the command line options and arguments.

Just make things easier ~

  • We want to make things easier.
  • We just want it to do the job that it needs to do.
  • We don't want to add any features that are way beyond its core task.

Get Started


using System.Collections.Generic;
using Xunit;

namespace Easy.CommandLine.Tests
{
    public class OptionContextTests
    {
        private readonly IOptionContext _context;

        public OptionContextTests()
        {
            _context = new OptionContext();

            // -a, -all
            _context.AddOption(new Option('a', "all", false));

            // -B, --block-size=SIZE
            var set = new HashSet<string>(new List<string>
            {
                "m", "M",
                "b", "B",
                "k", "K",
                "g", "G",
                "p", "P"
            });
            _context.AddOption(new Option('B', "block-size", true)
            {
                ArgumentValidator = a => set.Contains(a)
            });

            // --both
            _context.AddOption(new Option("both", false));
        }

        [Fact]
        public void Test()
        {
            _context.Reset();
            _context.Parse("-aBG", "--block-size=M", "--block-size=B", "--both", "hello", "world");

            var option = _context.GetOption('a');
            Assert.NotNull(option);
            Assert.True(option.IsSpecified);
            Assert.False(option.IsArgumentRequired);

            option = _context.GetOption("all");
            Assert.NotNull(option);
            Assert.True(option.IsSpecified);
            Assert.False(option.IsArgumentRequired);

            option = _context.GetOption('B');
            Assert.NotNull(option);
            Assert.True(option.IsSpecified);
            Assert.True(option.IsArgumentRequired);
            Assert.Equal("B", option.Argument);

            option = _context.GetOption("block-size");
            Assert.NotNull(option);
            Assert.True(option.IsSpecified);
            Assert.True(option.IsArgumentRequired);
            Assert.Equal("B", option.Argument);

            option = _context.GetOption("both");
            Assert.NotNull(option);
            Assert.True(option.IsSpecified);
            Assert.False(option.IsArgumentRequired);

            var arguments = _context.GetArguments();
            Assert.NotNull(arguments);
            Assert.Contains("hello", arguments);
            Assert.Contains("world", arguments);
            Assert.DoesNotContain("x", arguments);
        }
    }
}

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net5.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.0 357 9/7/2021

Publish 1.0.0