forked from Azure/azure-sdk-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharedOptions.cs
More file actions
105 lines (91 loc) · 3.44 KB
/
SharedOptions.cs
File metadata and controls
105 lines (91 loc) · 3.44 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System.CommandLine;
using System.CommandLine.Parsing;
using System.IO.Enumeration;
using Azure.Sdk.Tools.Cli.Tools;
using Azure.Sdk.Tools.Cli.Tools.HelloWorldTool;
using Azure.Sdk.Tools.Cli.Tools.HostServer;
using Azure.Sdk.Tools.Cli.Tools.ReleaseReadiness;
namespace Azure.Sdk.Tools.Cli.Commands
{
public static class SharedOptions
{
public static readonly List<Type> ToolsList = [
typeof(CleanupTool),
typeof(LogAnalysisTool),
typeof(HostServerTool),
typeof(PipelineAnalysisTool),
typeof(PipelineDetailsTool),
typeof(PipelineTestsTool),
typeof(ReleasePlanTool),
typeof(ReleaseReadinessTool),
typeof(SpecCommonTools),
typeof(SpecPullRequestTools),
typeof(SpecWorkflowTool),
typeof(SpecValidationTools),
typeof(TestAnalysisTool),
#if DEBUG
// only add this tool in debug mode
typeof(HelloWorldTool),
#endif
];
public static Option<string> ToolOption = new("--tools")
{
Description = "If provided, the tools server will only respond to CLI or MCP server requests for tools named the same as provided in this option. Glob matching is honored.",
IsRequired = false,
};
public static Option<string> Format = new(["--output", "-o"], () => "plain")
{
Description = "The format of the output. Supported formats are: plain, json",
IsRequired = false,
};
public static Option<bool> Debug = new(["--debug"], () => false)
{
Description = "Enable debug logging",
IsRequired = false,
};
public static (string, bool) GetGlobalOptionValues(string[] args)
{
var root = new RootCommand
{
TreatUnmatchedTokensAsErrors = false
};
root.AddGlobalOption(Format);
root.AddGlobalOption(Debug);
var parser = new Parser(root);
var result = parser.Parse(args);
var raw = result.GetValueForOption(Format)?.ToLowerInvariant() ?? "";
var debug = result.GetValueForOption(Debug);
return (raw, debug);
}
public static string[] GetToolsFromArgs(string[] args)
{
var root = new RootCommand
{
TreatUnmatchedTokensAsErrors = false
};
root.AddOption(ToolOption);
var parser = new Parser(root);
var result = parser.Parse(args);
var raw = result.GetValueForOption(ToolOption);
if (string.IsNullOrWhiteSpace(raw))
{
return new string[] { };
}
return raw
.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Select(s => s.ToLowerInvariant())
.ToArray();
}
public static List<Type> GetFilteredToolTypes(string[] args)
{
var toolMatchList = SharedOptions.GetToolsFromArgs(args);
if (toolMatchList.Length > 0)
{
return ToolsList
.Where(t => toolMatchList.Any(x => FileSystemName.MatchesSimpleExpression(x, t.Name) || t.Name.StartsWith("HostServer")))
.ToList();
}
return ToolsList;
}
}
}