Directives#
Directives are special arguments enabling cross cutting features. We've loosely followed the pattern defined by System.CommandLine to start with two directives, Debug & Parse.
Directives are a great way to add troubleshooting tools to your application. See Custom Directives at the bottom of this page for tips on adding your own.
How to use#
Directives must be the first arguments, enclosed by square brackets and will be removed from the arguments list during tokenization. After the first non-directive token is processed, any following tokens with square brackets will be processed as commands and operand values.
dotnet example.dll [some-directive] -v [not-a-directive]
To disable the directives feature entirely, set AppSettings.DisableDirectives = true
. This is only needed if an application has starting arguments enclosed by square brackets and using the argument separator is not a suitable solution.
Custom directives#
Directives are middleware components.
See the implementations of Debug
and Parse directives
for examples.
The presence of a directive is checked with commandContext.Tokens.TryGetDirective("debug", out _))
. The out parameter will include the entire string within the square brackets. Using a possible logging directive [log:debug]
, the out parameter value would be log:debug
. You can parse the value however you'd like.