Sub_Verbs - deniszykov/commandline GitHub Wiki
Some application require complex API where verbs are nested and grouped for clarity. For example, this is a hypothetical finance application:
myfinance Report Recalculate --id 0a0e0000000
myfinance Report Publish
myfinance Account ShowBalance --id 0a0e0000000
It has two nested verbs Report and Account. You can create such an API using nested verbs.
The nested verb must be declared in a specific way. It must take one ICommandLineBuilder
parameter and use the following method body:
// sync sub-verb
public static int Account(ICommandLineBuilder subVerbBuilder)
{
return subVerbBuilder
.Use<AccountApi>()
.Run();
}
// async sub-verb
public static Task<int> Report(ICommandLineBuilder subVerbBuilder, CancellationToken cancellationToken)
{
return subVerbBuilder
.Use<ReportApi>()
.RunAsync(cancellationToken);
}
Where AccountApi is class with list of sub-verbs of Account
verb.