Skip to content
ConsoleMonster

Coming from System.CommandLine

Move a parser from System.CommandLine to ConsoleMonster.Commands, keeping its commands, options and arguments, with a side-by-side map of the API.

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.CommandLineConsoleMonster.CommandsNote
RootCommandCommandApp(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.ZeroOrMoreListOption<T>, ListArgument<T> or an array typeA 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 optionImplicitValue--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 = _ =&gt; valueDefaultValue or DefaultValueFactoryThe factory takes no argument.
Required = trueRequired = true; an argument is required unless Optional or it has a default
AcceptOnlyFromAmong(...)AcceptOnly(...)Listed values show in help as --mode &lt;fast|thorough&gt;.
Validators.Add(result =&gt; result.AddError(...))Validate(value =&gt; message), Command.Validate(check =&gt; ...)Return a message to reject the value; command validators see every value.
CustomParserParserThrow FormatException with a readable message to reject the text.
Hidden, RecursiveHidden, Recursive
CompletionSources.Add(...)Completions = context =&gt; ...Listed values and enumerations complete without one.
root.Parse(args).InvokeAsync()app.RunAsync(args), or app.Parse(args) then app.InvokeAsync(result)
TreatUnmatchedTokensAsErrors = falseAllowUnmatchedTokens = trueUnmatched tokens keep their order in UnmatchedTokens.
Response files (@file)Response files (@file), on by default (ResponseFiles)
dotnet-suggest and the [suggest] directiveShellCompletion = true and completion <shell>The tool writes its own script for bash, zsh, fish and PowerShell.

What changes

  • Help is a page. --help draws a HelpView with the theme, groups (Group), defaults, listed values and examples (Command.Examples). CommandHelp.CreateTopic returns 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 (its TerminalProfile.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 an ExceptionView and 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), TimeSpan as 30s or 1h30m, dates, Guid, Version, Uri, FileInfo, DirectoryInfo and arrays of them need no parser, and the package works with trimming and native AOT.
  • Switches combine. -xvf archive.tar is -x -v -f archive.tar in both parsers, and -vfarchive.tar gives the rest of the word to the option that takes a value.
  • Values can come from elsewhere. ValueSource supplies 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 the completion command and the hidden word the scripts call.

Moving a tool

  1. Swap the package: dotnet remove package System.CommandLine, then dotnet add package ConsoleMonster.Commands.
  2. Change using System.CommandLine; to using ConsoleMonster.Commands; and RootCommand to CommandApp, giving it the executable's name.
  3. Rename the members in the map above. The compiler finds each one.
  4. Run the tool's own tests and check scripts that read its exit code after a usage error.
  5. Set ShellCompletion = true and add the completion line to the shell profile to keep Tab completion.

Next

Edit this page on GitHub