Skip to content

Arguments and Flags

Command inputs are plain C# classes whose properties are mapped to arguments and flags.

Defining an Input Class

cs
public class BuildInput
{
    [Description("The target configuration")]
    public string Configuration { get; set; } = "Debug";

    [Description("The output directory")]
    public string OutputPath { get; set; } = "./bin";

    [FlagAlias("verbose", 'v')]
    [Description("Enable verbose output")]
    public bool VerboseFlag { get; set; }

    [FlagAlias("force", 'f')]
    [Description("Force a clean rebuild")]
    public bool ForceFlag { get; set; }

    [Description("Maximum degree of parallelism")]
    public int ParallelCount { get; set; } = 4;
}

snippet source | anchor

cs
public class BuildInput
{
    [Description("The target configuration")]
    public string Configuration { get; set; } = "Debug";

    [Description("The output directory")]
    public string OutputPath { get; set; } = "./bin";

    [FlagAlias("verbose", 'v')]
    [Description("Enable verbose output")]
    public bool VerboseFlag { get; set; }

    [FlagAlias("force", 'f')]
    [Description("Force a clean rebuild")]
    public bool ForceFlag { get; set; }

    [Description("Maximum degree of parallelism")]
    public int ParallelCount { get; set; } = 4;
}

snippet source | anchor

Arguments

Public properties that are not suffixed with Flag are treated as positional arguments. They are matched in the order they appear on the class.

  • Required arguments -- Non-nullable properties without a default value
  • Optional arguments -- Properties with a default value

Flags

Properties whose names end with Flag are treated as command line flags (options).

Flag Aliases

Use [FlagAlias] to define short and long flag names:

csharp
[FlagAlias("verbose", 'v')]
public bool VerboseFlag { get; set; }

This allows both --verbose and -v on the command line.

Flag Types

.NET TypeCLI SyntaxExample
bool--flag--verbose
string--flag value--output ./bin
int--flag value--parallel 8
Enum--flag value--level Debug

Description Attribute

Use [Description] on properties to provide help text displayed in the CLI:

csharp
[Description("The target configuration")]
public string Configuration { get; set; } = "Debug";

Next Steps

Released under the MIT License.