-
Notifications
You must be signed in to change notification settings - Fork 9
Option Ordering
Matthias Beerens edited this page Apr 11, 2021
·
1 revision
Order options in the command line
Add the OptionOrder
attribute or Order
Fluent API Method.
Options are sorted from lowest to highest.
using MatthiWare.CommandLine;
using MatthiWare.CommandLine.Core.Attributes;
static void Main(string[] args)
{
var parser = new CommandLineParser<OrderedOptions>();
var result = parser.Parse(args);
var options = result.Result;
Console.WriteLine($"Input: {options.InputPath}");
Console.WriteLine($"Output: {options.OutputPath}");
Console.ReadKey();
}
public class OrderedOptions
{
[OptionOrder(0)]
public string InputPath { get; set; }
[OptionOrder(1)]
public string OutputPath { get; set; }
}
using MatthiWare.CommandLine;
using MatthiWare.CommandLine.Core.Attributes;
static void Main(string[] args)
{
var parser = new CommandLineParser<OrderedOptions>();
parser
.Configure(_ => _.InputPath)
.Order(0);
parser
.Configure(_ => _.OutputPath)
.Order(1);
var result = parser.Parse(args);
var options = result.Result;
Console.WriteLine($"Input: {options.InputPath}");
Console.WriteLine($"Output: {options.OutputPath}");
Console.ReadKey();
}
public class OrderedOptions
{
public string InputPath { get; set; }
public string OutputPath { get; set; }
}
Input:
> Example.exe "input path" "output path"
Output:
Input: Input path
Output: output path