forked from dotnet/command-line-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelpAnnotationExtensions.cs
67 lines (60 loc) · 3.08 KB
/
HelpAnnotationExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.CommandLine.Subsystems;
using System.CommandLine.Subsystems.Annotations;
namespace System.CommandLine;
public static class HelpAnnotationExtensions
{
/// <summary>
/// Sets the help description on the <paramref name="symbol"/>
/// </summary>
/// <typeparam name="TSymbol">The type of the symbol</typeparam>
/// <param name="symbol">The symbol</param>
/// <param name="description">The help description for the symbol</param>
/// <returns>The <paramref name="symbol">, to enable fluent construction of symbols with annotations.</returns>
public static TSymbol WithDescription<TSymbol> (this TSymbol symbol, string description) where TSymbol : CliSymbol
{
symbol.SetDescription(description);
return symbol;
}
/// <summary>
/// Sets the help description on the <paramref name="symbol"/>
/// </summary>
/// <typeparam name="TSymbol">The type of the symbol</typeparam>
/// <param name="symbol">The symbol</param>
/// <param name="description">The help description for the symbol</param>
public static void SetDescription<TSymbol>(this TSymbol symbol, string description) where TSymbol : CliSymbol
{
symbol.SetAnnotation(HelpAnnotations.Description, description);
}
/// <summary>
/// Get the help description on the <paramref name="symbol"/>
/// </summary>
/// <typeparam name="TSymbol">The type of the symbol</typeparam>
/// <param name="symbol">The symbol</param>
/// <returns>The symbol description if any, otherwise <see langword="null"/></returns>
/// <remarks>
/// This is intended to be called by CLI authors. Subsystem authors should instead call
/// <see cref="GetDescription{TSymbol}(AnnotationResolver, TSymbol)"/> to get values from
/// the pipeline's <see cref="Pipeline.Annotations"/>, which takes dynamic providers into account.
/// </remarks>
public static string? GetDescription<TSymbol>(this TSymbol symbol) where TSymbol : CliSymbol
{
return symbol.GetAnnotationOrDefault<string>(HelpAnnotations.Description);
}
/// <summary>
/// Get the help description for the <paramref name="symbol"/> from the <paramref name="resolver"/>,
/// which takes dynamic providers into account.
/// </summary>
/// <typeparam name="TSymbol">The type of the symbol</typeparam>
/// <param name="symbol">The symbol</param>
/// <returns>The symbol description if any, otherwise <see langword="null"/></returns>
/// <remarks>
/// This is intended to be called by subsystem authors. CLI authors should instead call
/// <see cref="GetDescription{TSymbol}(TSymbol)"/> to get the value associated directly with the symbol.
/// </remarks>
public static string? GetDescription<TSymbol>(this AnnotationResolver resolver, TSymbol symbol) where TSymbol : CliSymbol
{
return resolver.GetAnnotationOrDefault<string>(symbol, HelpAnnotations.Description);
}
}