Files
dualfroz 5e1eff9f24 feat: add command usage examples
Add an Examples string array property to CommandAttribute so command authors can document example invocations. Each example contains only the arguments that follow the command name; the executable and command name are prepended automatically when the example is rendered.

Examples are rendered as extra lines in the USAGE section of the help text. The source generator resolves the values from the attribute and emits them into the command descriptor consumed at runtime.
2026-08-28 10:12:58 +02:00

44 lines
1.4 KiB
C#

using System;
namespace CliFx.Binding;
/// <summary>
/// Binds a type to a command.
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class CommandAttribute(string? name) : Attribute
{
/// <summary>
/// Initializes an instance of <see cref="CommandAttribute" />.
/// </summary>
public CommandAttribute()
: this(null) { }
/// <summary>
/// Command name.
/// </summary>
/// <remarks>
/// Command can have no name, in which case it's treated as the application's default (i.e., root) command.
/// Only one default command is allowed to be registered in an application.
/// All commands registered in an application must have unique names (comparison IS NOT case-sensitive).
/// </remarks>
public string? Name { get; } = name;
/// <summary>
/// Command description.
/// Used for display purposes in the help text.
/// </summary>
public string? Description { get; set; }
/// <summary>
/// Usage examples of the command.
/// Used for display purposes in the help text.
/// </summary>
/// <remarks>
/// Each example should only contain the parameters and options that come after the
/// command name; the command name itself is prepended automatically when the example
/// is rendered in the help text.
/// </remarks>
public string[] Examples { get; set; } = [];
}