System.CommandLine is Microsoft's command-line parser and an active project; this guide makes no claim that it is going away. It is for tools that already draw their output with ConsoleMonster and want the parser, the help and the errors to look and behave the same way. ConsoleMonster.Commands uses the same shape (a root command, subcommands, typed options and arguments, an action per command), so most of a move is renaming. It is an API migration, not a drop-in replacement: the namespaces and a few member names differ.
The examples were checked against System.CommandLine 3.0.0 and ConsoleMonster.Commands on 6 December 2026.
The same tool in both
The left side imports System.CommandLine, the right side ConsoleMonster.Commands; both also use System and System.Threading.Tasks.
System.CommandLine
Argument<string> domain = new("domain") { Description = "The domain to check." };
Option<int> depth = new("--depth", "-d") {
Description = "How many levels to follow.",
DefaultValueFactory = _ => 3
};
depth.Validators.Add(result => {
if (result.GetValueOrDefault<int>() is < 1 or > 10) {
result.AddError("The depth must be between 1 and 10.");
}
});
Option<string> mode = new("--mode") {
Description = "How hard to look.",
DefaultValueFactory = _ => "fast"
};
mode.AcceptOnlyFromAmong("fast", "thorough");
Option<bool> verbose = new("--verbose", "-v") { Recursive = true };
Command scan = new("scan", "Checks a domain.") { domain, depth, mode };
scan.SetAction(async (parseResult, cancellationToken) => {
Console.WriteLine($"{parseResult.GetValue(domain)} {parseResult.GetValue(depth)}");
await Task.Delay(10, cancellationToken);
return 0;
});
RootCommand root = new("Checks DNS.") { verbose, scan };
return await root.Parse(args).InvokeAsync();
ConsoleMonster.Commands
Argument<string> domain = new("domain") { Description = "The domain to check." };
Option<int> depth = new Option<int>("--depth", "-d") {
Description = "How many levels to follow.",
DefaultValue = 3
}.Validate(value => value is < 1 or > 10 ? "The depth must be between 1 and 10." : null);
Option<string> mode = new Option<string>("--mode") {
Description = "How hard to look.",
DefaultValue = "fast"
}.AcceptOnly("fast", "thorough");
Option<bool> verbose = new("--verbose", "-v") { Recursive = true };
Command scan = new("scan", "Checks a domain.") { domain, depth, mode };
scan.SetAction(async (parseResult, cancellationToken) => {
Console.WriteLine($"{parseResult.GetValue(domain)} {parseResult.GetValue(depth)}");
await Task.Delay(10, cancellationToken);
return 0;
});
CommandApp app = new("dnscheck", "Checks DNS.") { verbose, scan };
app.ShellCompletion = true;
return await app.RunAsync(args);
The action keeps its (parseResult, cancellationToken) signature, so action bodies move unchanged. The other SetAction overloads take a CommandContext with the same GetValue calls and the cancellation token.
API map
| System.CommandLine | ConsoleMonster.Commands | Note |
|---|---|---|
RootCommand | CommandApp(name, description) | The root is named as the executable, for help and completion scripts. |
Command, Option<T>, Argument<T> | Command, Option<T>, Argument<T> | Same names and collection initialisers; aliases follow the name. |
Arity = ArgumentArity.ZeroOrMore | ListOption<T>, ListArgument<T> or an array type | A list argument needs Optional = true to allow none; a list option given on the line needs a value. Separator and TakesFollowingValues read --tag a,b and --tag a b. |
Arity = ArgumentArity.ZeroOrOne with a CustomParser for the bare option | ImplicitValue | --log gives the implicit value and --log=warn the given one. --log warn works when warn is a listed value or converts to the type; a string option or one with its own Parser, without listed values, needs the =. |
DefaultValueFactory = _ => value | DefaultValue or DefaultValueFactory | The factory takes no argument. |
Required = true | Required = true; an argument is required unless Optional or it has a default | |
AcceptOnlyFromAmong(...) | AcceptOnly(...) | Listed values show in help as --mode <fast|thorough>. |
Validators.Add(result => result.AddError(...)) | Validate(value => message), Command.Validate(check => ...) | Return a message to reject the value; command validators see every value. |
CustomParser | Parser | Throw FormatException with a readable message to reject the text. |
Hidden, Recursive | Hidden, Recursive | |
CompletionSources.Add(...) | Completions = context => ... | Listed values and enumerations complete without one. |
root.Parse(args).InvokeAsync() | app.RunAsync(args), or app.Parse(args) then app.InvokeAsync(result) | |
TreatUnmatchedTokensAsErrors = false | AllowUnmatchedTokens = true | Unmatched tokens keep their order in UnmatchedTokens. |
Response files (@file) | Response files (@file), on by default (ResponseFiles) | |
dotnet-suggest and the [suggest] directive | ShellCompletion = true and completion <shell> | The tool writes its own script for bash, zsh, fish and PowerShell. |
What changes
- Help is a page.
--helpdraws aHelpViewwith the theme, groups (Group), defaults, listed values and examples (Command.Examples).CommandHelp.CreateTopicreturns the same page as data for other renderers. - Errors use the error output's language. Parse errors and the line pointing to help follow the language of
ErrorOutput(itsTerminalProfile.Language): English, Polish, German, Spanish, French or Italian, the same languages as the rest of ConsoleMonster. System.CommandLine ships its messages in more languages. - Exit codes are fixed. A parse error exits with 2 (
ExitCode.Usage) where System.CommandLine uses 1; an unhandled exception is drawn as anExceptionViewand exits with 1; Ctrl+C exits with 130. Scripts that test for 1 after a typo need the new number. - Values convert without reflection. Numbers, enumerations (written in kebab case),
TimeSpanas30sor1h30m, dates,Guid,Version,Uri,FileInfo,DirectoryInfoand arrays of them need no parser, and the package works with trimming and native AOT. - Switches combine.
-xvf archive.taris-x -v -f archive.tarin both parsers, and-vfarchive.targives the rest of the word to the option that takes a value. - Values can come from elsewhere.
ValueSourcesupplies values the line left out, such as settings from a file, before required options are checked.app.Use((context, next) => ...)wraps every action. - No directives. ConsoleMonster.Commands has no
[diagram]or[suggest]directives; completion goes through thecompletioncommand and the hidden word the scripts call.
Moving a tool
- Swap the package:
dotnet remove package System.CommandLine, thendotnet add package ConsoleMonster.Commands. - Change
using System.CommandLine;tousing ConsoleMonster.Commands;andRootCommandtoCommandApp, giving it the executable's name. - Rename the members in the map above. The compiler finds each one.
- Run the tool's own tests and check scripts that read its exit code after a usage error.
- Set
ShellCompletion = trueand add thecompletionline to the shell profile to keep Tab completion.
Next
- Command-line tools: every option, the help page, completion and
CommandBinding<TSettings>. - Coming from System.CommandLine.Rendering: replace the retired rendering package with widgets and live regions.
- Coming from Spectre.Console: rendering, prompts and live output.