-
Notifications
You must be signed in to change notification settings - Fork 13
Getting started
Typin is a simple to use, yet powerful framework for building both interactive command line applications and command line tools. It is build based on the code of CliFx. Its main goal is to provide an enjoyable, similar to ASP.NET Core, development experience when building command line applications.
It supports an argument syntax which is based on the POSIX standard. Order of arguments is semantically important and it always goes like this:
{directives} {command name} {parameters} {options}
Install the package via NuGet: dotnet add package Typin
To turn your application into a command line interface you need to change your program's Main
method so that it delegates execution to CliApplication
. The code below will create and run a default CliApplication
that will resolve commands defined in the calling assembly. Using fluent interface provided by CliApplicationBuilder
you can also easily configure different aspects of your application.
public static class Program
{
public static async Task<int> Main() =>
await new CliApplicationBuilder()
.AddCommandsFromThisAssembly()
.Build()
.RunAsync();
}
It is also possible to use a startup class to configure application.
public static class Program
{
public static async Task<int> Main() =>
await new CliApplicationBuilder()
.UseStartup<CliStartup>()
.Build()
.RunAsync();
}
public class CliStartup : ICliStartup
{
public void ConfigureServices(IServiceCollection services)
{
// Register services
services.AddSingleton<ICustomService, CustomService>();
}
public void Configure(CliApplicationBuilder app)
{
app.AddCommandsFromThisAssembly()
.AddDirective<DebugDirective>()
.AddDirective<PreviewDirective>()
.UseInteractiveMode();
}
}
Getting started
Advanced features
- Reporting errors
- Exception handling
- Metadata and startup message
- Graceful cancellation
- Dependency injection
- Middleware pipeline
- Environment variables
Utilities
Tests
Misc