-
Notifications
You must be signed in to change notification settings - Fork 85
Roadmap
automatically create a defined object type and setup individual Options for each strongly-typed property.
For example:
public class ApplicationArguments
{
public int RecordId { get; set; }
public bool Silent { get; set; }
public string NewValue { get; set; }
}
we can parse strongly types values directly to a built instance of the type using the FluentCommandLineBuilder
// create a builder for the ApplicationArguments type
var b = new FluentCommandLineBuilder<ApplicationArguments>();
// specify which property the value will be assigned too.
b.Setup(arg => arg.RecordId)
.As('r', "record") // define the short and long option name
.Required();
b.Setup(arg => arg.NewValue)
.As('v', "value")
.Required();
b.Setup(arg => arg.Silent)
.As('s', "silent")
.SetDefault(false); // use the standard fluent Api to define expected behaviour
var result = b.Parse(args);
if(result.HasErrors == false)
{
// get the create object from the Object property on the builder.
application.Run(b.Object);
}
In v1.1 and earlier, to setup an Option a short name must always be supplied. This has now been changed so Options with just long names can also be created.
The validation invoked when setting up new Options has been re-factored and improved. More meaningful error message will now be thrown when called with invalid data.
Some functional changes have been made which may impact existing behaviour.
A InvalidOptionNameException
is now thrown when setting up an Option if:
- A specified long Option name is a single char in length.
- A specified long Option name contains
:
or=
characters anywhere within it.
Short and long Options are now case sensitive. This means that -s
and -S
are considered different, also long Options --long
and --LONG
are considered different.
Changes have been kept to a minimal with the following changes made:
-
Setup<T>(string, string)
has been made obsolete, being replaced instead withSetup<T>(char, string)
. This is to better reflect through the Api that short Options should be a single character only. -
Setup<T>(string)
is no longer used to setup an Option with only a short name. Instead it is used to setup an Option with only a long name. This will initially result in anInvalidOptionNameException
raised when the method is invoked as long names must now be longer than a single character in length. If you require to setup an option with a short name only you should use theSetup<T>(char)
overload instead.