Colipars 0.12.0

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

// Install Colipars as a Cake Tool
#tool nuget:?package=Colipars&version=0.12.0

colipars

COmmand LIne PARSer

Another library for parsing command line arguments using C#. Depends on .Net Standard 2.0

Has a default implementation to output to the console and get its configuration from attributes on a classes, but can be extended to output to something else or fetch its configuration from configuration files or other sources.

Examples

Named arguments

create --name test -d 0.42
[Verb("create")]
class CreateCommand
{
    [NamedOption("name", Description = "Name of the element to create")]
    public string Name { get; set; }

    [NamedOption("double", Alias = "d", Description = "A floating point value.")]
    public double Number { get; set; }
}

Positional arguments

setPosition 0.40 -100
[Verb("setPosition")]
class SetPositionCommand
{
    [PositionalOption(0, Description = "X coordinate")]
    public float X { get; set; }

    [PositionalOption(1, Description = "Y coordinate")]
    public float Y { get; set; }
}

Lists and flags with custom converters

Supports flags and lists with custom converters based on TypeConverters.

convert -vvv -names Alfred Freddy Jason
[Verb("convert")]
class ConvertCommand
{
    [CollectionTypeConverter(typeof(UserConverter))]
    [NamedCollectionOption("names", Alias = "n")]
    public ICollection<User> Users { get; } = new List<User>();

    [TypeConverter(typeof(VerbosityLevelConverter))]
    [FlagOption("verbosity", ShortHand = "v")]
    public VerbosityLevel Verbosity { get; set; }
}

Uses a special CollectionTypeConverter attribute to specify a converter for the elements of a collection instead of the whole collection.

How to use

var exitCode = Parsers.Setup.ClassAttributes<Command>().Parse(args).Map(
    (Command command) => command.Execute(),
    (IEnumerable<IError> errors) => 1
);
var command = Parsers.Setup.ClassAttributes<Command>().Parse(args).GetCustomObject<Command>();

Help can be shown by using the -h flag or from code, this includes the description of the attributes.

Parsers.Setup.ClassAttributes<Command>().ShowHelp();

Configuration

If a default command is specified, the verb doesn't have to be specified at the beginning of the argument list.

Parsers.Setup.ClassAttributes<ConvertCommand>((c) => c.UseAsDefault<ConvertCommand>());

Per default, the local use always CultureInfo.InvariantCulture, that can be changed in a similar way.

Parsers.Setup.ClassAttributes<SetPositionCommand>((c) => c.CultureInfo = CultureInfo.CurrentCulture);

Method verbs

It's possible to use the Verb attributes not only on classes but also on methods.

class MyContainer
{
    [Verb("handleNumbers")]
    public int HandleNumbers([NamedCollectionOption("numbers")] IEnumerable<int> numbers)
    {
        ...
        return 0;
    }
}
Parsers.Setup.MethodAttributes<MyContainer>().Parse(args).Execute();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  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.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.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
0.12.0 718 4/7/2020
0.11.0 546 9/24/2019
0.10.0 1,089 1/25/2018
0.9.1 1,014 1/2/2018
0.9.0 1,202 11/10/2017

- added option to show the help if no arguments have been given
- changing services when setting up parsers does not influence the global service list
- changed the error handler service from an interface to a delegate