Skip to content

Option Clustering

Matthias Beerens edited this page Apr 11, 2021 · 1 revision

Option Clustering

It is possible to parse clustered options.

Configure clustered options

This is done by convention, nothing has to be done on the configuration side.

The user will automatically be able to use clustered options if the following conditions are met:

  • Have a model with at least 2 (or more) properties of the same type
  • All these properties need to have a shortname of 1 character

Example

using MatthiWare.CommandLine;
using MatthiWare.CommandLine.Core.Attributes;

static void Main(string[] args)
{
    var parser = new CommandLineParser<ClusteredOptions>();

    var result = parser.Parse(args);

    var options = result.Result;

    Console.WriteLine($"A: {options.A}");
    Console.WriteLine($"B: {options.B}");
    Console.WriteLine($"C: {options.C}");

    Console.ReadKey();
}

public class ClusteredOptions
{
    [Name("a"), Required]
    public int A { get; set; }

    [Name("b"), Required]
    public int B { get; set; }

    [Name("c"), Required]
    public int C { get; set; }
}

Usage

Input:
> Example.exe -abc 123

Output:
A: 123
B: 123
C: 123