-
Notifications
You must be signed in to change notification settings - Fork 0
Configuring AtleX.CommandLineParameters
AtleX.CommandLineArguments features a rich and easy to use configuration system with which you can control its behaviour.
There are two ways of configuring Atlex.CommandLineArguments. The first is to create a strongly typed configuration by extending CommandLineArgumentsConfiguration. This is especially useful for organisations that wish to standardise their configuration, since they can wrap it up in a NuGet package and use that throughout the organisation.
public class MyConfiguration : CommandLineArgumentsConfiguration
{
public MyConfiguration()
{
this.HelpWriter = new WindowsStyleHelpWriter();
this.Parser = new WindowsStyleCommandLineArgumentsParser();
this.Validators.Add(new RequiredArgumentValidator());
this.TypeParsers.Add(new BoolTypeParser());
this.TypeParsers.Add(new StringTypeParser());
}
}The second one is by just instantiating the CommandLineArgumentsConfiguration directly and configuring it.
var configuration = new CommandLineArgumentsConfiguration();This creates a new configuration with the built-in validators and type parsers. You can add custom ones by calling .Add().
configuration.Add(new CustomValidator()); // Adds a custom IArgumentValidator implementation
configuration.Add(new CustomTypeParser()); // Adds a custom ITypeParser implementationThere are overrides of .Add() available that accept enumerables of IArgumentValidator and ITypeParser.
Once the configuration is created you must assign is to CommandLineArguments.Configuration before calling CommandLineArguments.TryParse().
CommandLineArguments.Configuration = new MyConfiguration; // or assign the result of the ConfigurationBuilder
if (!CommandLineArguments.TryParse(args, out MyArguments arguments))
{
}