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.
This commit is contained in:
1 parent
e3e64a40e4
commit
8f11b8ff38
6 files changed
+132
-3
No files matched your search
@@ -31,6 +31,17 @@ internal static class CommandDescriptor
|
||||
""";
|
||||
}
|
||||
|
||||
private static string EmitExamples(IReadOnlyList<string> examples)
|
||||
{
|
||||
if (examples.Count == 0)
|
||||
return "global::System.Array.Empty<string>()";
|
||||
|
||||
// lang=csharp
|
||||
return $$"""
|
||||
new[] { {{string.Join(", ", examples.Select(CSharp.Encode))}} }
|
||||
""";
|
||||
}
|
||||
|
||||
private static string? TryEmitDefaultScalarConverter(ITypeSymbol type)
|
||||
{
|
||||
// Object
|
||||
@@ -522,6 +533,7 @@ internal static class CommandDescriptor
|
||||
new global::CliFx.Binding.CommandDescriptor<{{command.Type.GetGloballyQualifiedName()}}>(
|
||||
{{CSharp.Encode(command.Name)}},
|
||||
{{CSharp.Encode(command.Description)}},
|
||||
{{EmitExamples(command.Examples)}},
|
||||
new global::CliFx.Binding.CommandInputDescriptor[]
|
||||
{
|
||||
{{string.Join(",", command.Inputs
|
||||
|
||||
Reference in new issue
Block a user