-
Notifications
You must be signed in to change notification settings - Fork 418
Expand file tree
/
Copy pathActivities.cs
More file actions
46 lines (39 loc) · 1.51 KB
/
Activities.cs
File metadata and controls
46 lines (39 loc) · 1.51 KB
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
using System.Diagnostics;
namespace System.CommandLine;
internal static class DiagnosticsStrings
{
internal const string LibraryNamespace = "System.CommandLine";
internal const string ParseMethod = LibraryNamespace + ".Parse";
internal const string InvokeMethod = LibraryNamespace + ".Invoke";
internal const string InvokeType = "invoke.type";
internal const string Async = "async";
internal const string Sync = "sync";
internal const string ExitCode = "exitcode";
internal const string Exception = "exception";
internal const string Errors = "errors";
internal const string Command = "command";
}
internal static class Activities
{
internal static readonly ActivitySource ActivitySource = new ActivitySource(DiagnosticsStrings.LibraryNamespace);
}
internal static class ActivityExtensions
{
/// <summary>
/// Walks up the command tree to get the build the command name by prepending the parent command names to the 'leaf' command name.
/// </summary>
/// <param name="commandResult"></param>
/// <returns>The full command name, like 'dotnet package add'.</returns>
internal static string FullCommandName(this Parsing.CommandResult commandResult)
{
var command = commandResult.Command;
var path = command.Name;
while (commandResult.Parent is Parsing.CommandResult parent)
{
command = parent.Command;
path = $"{command.Name} {path}";
commandResult = parent;
}
return path;
}
}