v0.11.0
What's new?
[Breaking changes] Decouples the parser engine from the command provider
The way command are defined are now decoupled from the parser engine. This allow introducing another way to define commands. This release introduce MGR.CommandLineParser.Command.Lambda to define command defined on the fly which the execution is based on lambda.
The primary interface to implement is MGR.CommandLineParser.Extensibility.Command.ICommandTypeProvider.
Due to the decoupling, the IParser.Parse methods now returns a ParsingResult. Its main properties/methods are:
CommandObject: anICommandObjectthat represents the command,IsValid: a boolean that indicates if the parsing operation was successfull, and the command has no validation errors,ValidationResults: the list ofValidationResultExecuteAsync: the method that will execute the command is everything is correct.
[Breaking changes] The command execution are now asynchronous
The int ICommand.Execute() method is now Task<int> ICommand.ExecuteAsync().
Similary, the package MGR.CommandLineParser.Command.Lambda only define asynchronous commands.
[Breaking changes] Use Microsoft.Extensions.DependencyInjection
The library is now using the DI abstraction provided by Microsoft instead of the custom one. This will simplify defining commands that inject services.
The parser now requires a IServiceProvider when calling one of the parse methods. There is extensions methods that uses the default built-in service provider.
To use your own service provider with the library, you have to register the parser's services by calling AddCommandLineParser on your IServiceCollection. The method returns a CommandLineParserBuilder that allow you adding custom services (currently there is built-in methods to add custom ICommandTypeProvider: AddClassBasedCommands (the previous legacy behavior), AddCommands<TCommand> (adds all class-based commands on the assembly containing the TCommand class), and AddCommand from MGR.CommandLineParser.Command.Lambda package (add a lambda-based command).
Define your commands without creating a new class
The new MGR.CommandLineParser.Command.Lambda package allow you to define commands on the fly by using command.
You have to register the command to your own service provider to define lambda-based commands (see above).
Introduce integration with the new generic host
The new MGR.CommandLineParser.Hosting introduce integration with the new generic host APIs.
The integration has two part:
- Registering the parser's services: call
ConfigureParseron an instance ofIHostBuilder. You can register the command providers with this method. - Parse and execute the command: call
ParseCommandLineAndExecuteAsyncon either theIHostBuilderor theIHost. The result of this method is the parsing result, or the result of the command execution.
What else?
Use of Azure DevOps to build and release
The library now use Azure DevOps to build and release the library.