This is a presentation layer framework that helps you create a CLI (command line interface) applications.
ConsoleTools.Commando.Setup.Autofac- Note:
- The
ConsoleTools.Commandopackage will be automatically included.
- The
The public properties are automatically populated by the router with arguments from the user's CLI command.
When executed, the command returns a View Model instance.
[NamedCommand("read", Description = "Display the content of a text file.")]
internal class ReadFileCommand : IConsoleCommand<ReadFileViewModel>
{
[NamedParameter("file", ShortName = 'f', Description = "The full path of the file.")]
public string FilePath { get; set; }
public Task<ReadFileViewModel> Execute()
{
...
}
}The View Model class is a POCO containing the data to be displayed by the View.
internal class ReadFileViewModel
{
public string FilePath { get; set; }
public string Content { get; set; }
}The View Class must implement the IView<TViewModel> interface.
Alternatively, it may implement the base class ViewBase<TViewModel> which provide a number of helper methods to help display data in the console.
internal class ReadFileView : ViewBase<ReadFileViewModel>
{
public override void Display(ReadFileViewModel viewModel)
{
...
}
}Application application = ApplicationBuilder.Create()
.RegisterCommandsFrom(typeof(ReadFileCommand).Assembly) // Provide the assembly containing your commands.
.Build();
await application.RunAsync(args);