-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCommandAppExtensions.cs
139 lines (111 loc) · 7.77 KB
/
CommandAppExtensions.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
namespace Atc.CodingRules.Updater.CLI.Extensions;
public static class CommandAppExtensions
{
public static void ConfigureCommands(this CommandApp<RootCommand> app)
{
ArgumentNullException.ThrowIfNull(app);
app.Configure(config =>
{
ConfigureRunCommand(config);
ConfigureSanityCheckCommand(config);
config.AddBranch(CommandConstants.NameOptionsFile, ConfigureOptionsFileCommands());
config.AddBranch(NameCommandConstants.AnalyzerProviders, ConfigureAnalyzerProvidersCommands());
});
}
private static void ConfigureRunCommand(IConfigurator config)
=> config.AddCommand<RunCommand>(NameCommandConstants.Run)
.WithDescription("Update the project folder with ATC coding rules and configurations")
.WithExample([".", CreateEquivalentToRun(8)])
.WithExample([NameCommandConstants.Run, ".", CreateEquivalentToRun(4)])
.WithExample([NameCommandConstants.Run, CreateArgumentProjectPathWithDot(), CreateEquivalentToRun(1)])
.WithExample([NameCommandConstants.Run, CreateArgumentProjectPathWithTestFolder()])
.WithExample(
[
NameCommandConstants.Run,
CreateArgumentProjectPathWithTestFolder(),
CreateArgumentProjectTarget(SupportedProjectTargetType.DotNetCore),
ArgumentCommandConstants.LongUseTemporarySuppressions,
ArgumentCommandConstants.LongOrganizationName, "MyCompany",
ArgumentCommandConstants.LongRepositoryName, "MyRepo",
CommandConstants.ArgumentLongVerbose
]);
private static void ConfigureSanityCheckCommand(IConfigurator config)
=> config.AddCommand<SanityCheckCommand>(NameCommandConstants.SanityCheck)
.WithDescription("Sanity check the project files")
.WithExample([NameCommandConstants.SanityCheck, ".", CreateEquivalentToSanityCheck(8)])
.WithExample([NameCommandConstants.SanityCheck, CreateArgumentProjectPathWithTestFolder()])
.WithExample(
[
NameCommandConstants.SanityCheck,
CreateArgumentProjectPathWithTestFolder(),
CreateArgumentProjectTarget(SupportedProjectTargetType.DotNetCore),
CommandConstants.ArgumentLongVerbose
]);
private static Action<IConfigurator<CommandSettings>> ConfigureOptionsFileCommands()
=> node =>
{
node.SetDescription("Commands for the options file 'atc-coding-rules-updater.json'");
node
.AddCommand<OptionsFileCreateCommand>(CommandConstants.NameOptionsFileCreate)
.WithDescription("Create default options file 'atc-coding-rules-updater.json' if it doesn't exist")
.WithExample([CreateArgumentCommandsOptionsFileWithCreate(), ".", CreateEquivalentToOptionsFileCreate(6)])
.WithExample([CreateArgumentCommandsOptionsFileWithCreate(), CreateArgumentProjectPathWithDot(), CreateEquivalentToOptionsFileCreate(3)])
.WithExample([CreateArgumentCommandsOptionsFileWithCreate(), CreateArgumentProjectPathWithTestFolder()]);
node
.AddCommand<OptionsFileValidateCommand>(CommandConstants.NameOptionsFileValidate)
.WithDescription("Validate the options file 'atc-coding-rules-updater.json'")
.WithExample([CreateArgumentCommandsOptionsFileWithValidate(), ".", CreateEquivalentToOptionsFileValidate(4)])
.WithExample([CreateArgumentCommandsOptionsFileWithValidate(), CreateArgumentProjectPathWithTestFolder()]);
};
private static Action<IConfigurator<CommandSettings>> ConfigureAnalyzerProvidersCommands()
=> node =>
{
node.SetDescription("Commands for analyzer providers");
node
.AddCommand<AnalyzerProvidersCollectCommand>(NameCommandConstants.AnalyzerProvidersCollect)
.WithDescription("Collect base rules metadata from all Analyzer providers")
.WithExample([CreateArgumentCommandsAnalyzerProvidersWithCollect(), ".", CreateEquivalentToAnalyzerProvidersCollect(6)])
.WithExample([CreateArgumentCommandsAnalyzerProvidersWithCollect(), CreateArgumentProjectPathWithDot(), CreateEquivalentToAnalyzerProvidersCollect(3)])
.WithExample([CreateArgumentCommandsAnalyzerProvidersWithCollect(), CreateArgumentProjectPathWithTestFolder()])
.WithExample(
[
CreateArgumentCommandsAnalyzerProvidersWithCollect(),
CreateArgumentProjectPathWithTestFolder(),
CreateArgumentFetchMode(ProviderCollectingMode.ReCollect),
CommandConstants.ArgumentLongVerbose
]);
node
.AddCommand<AnalyzerProvidersCacheCleanupCommand>(NameCommandConstants.AnalyzerProvidersCleanupCache)
.WithDescription("Cleanup cache from Analyzer providers")
.WithExample([CreateArgumentCommandsAnalyzerProvidersWithCleanupCache()]);
};
private static string CreateArgumentProjectPathWithDot()
=> $"{ArgumentCommandConstants.ShortProjectPath} .";
private static string CreateArgumentProjectPathWithCurrentFolder()
=> $"{ArgumentCommandConstants.ShortProjectPath} [CurrentFolder]";
private static string CreateArgumentProjectPathWithTestFolder()
=> @$"{ArgumentCommandConstants.ShortProjectPath} c:\temp\MyProject";
private static string CreateArgumentProjectTarget(SupportedProjectTargetType targetType)
=> @$"{ArgumentCommandConstants.ShortProjectTarget} {targetType}";
private static string CreateArgumentFetchMode(ProviderCollectingMode collectingMode)
=> @$"{ArgumentCommandConstants.LongFetchMode} {collectingMode}";
private static string CreateArgumentCommandsAnalyzerProvidersWithCollect()
=> $"{NameCommandConstants.AnalyzerProviders} {NameCommandConstants.AnalyzerProvidersCollect}";
private static string CreateArgumentCommandsOptionsFileWithCreate()
=> $"{CommandConstants.NameOptionsFile} {CommandConstants.NameOptionsFileCreate}";
private static string CreateArgumentCommandsOptionsFileWithValidate()
=> $"{CommandConstants.NameOptionsFile} {CommandConstants.NameOptionsFileValidate}";
private static string CreateArgumentCommandsAnalyzerProvidersWithCleanupCache()
=> $"{NameCommandConstants.AnalyzerProviders} {NameCommandConstants.AnalyzerProvidersCleanupCache}";
private static string CreateEquivalentToRun(int indentSpaces)
=> PrefixSpaces(indentSpaces, $"(equivalent to '{NameCommandConstants.Run} {CreateArgumentProjectPathWithCurrentFolder()}')");
private static string CreateEquivalentToSanityCheck(int indentSpaces)
=> PrefixSpaces(indentSpaces, $"(equivalent to '{NameCommandConstants.SanityCheck} {CreateArgumentProjectPathWithCurrentFolder()}')");
private static string CreateEquivalentToOptionsFileCreate(int indentSpaces)
=> PrefixSpaces(indentSpaces, $"(equivalent to '{CreateArgumentCommandsOptionsFileWithCreate()} {CreateArgumentProjectPathWithCurrentFolder()}')");
private static string CreateEquivalentToOptionsFileValidate(int indentSpaces)
=> PrefixSpaces(indentSpaces, $"(equivalent to '{CreateArgumentCommandsOptionsFileWithValidate()} {CreateArgumentProjectPathWithCurrentFolder()}')");
private static string CreateEquivalentToAnalyzerProvidersCollect(int indentSpaces)
=> PrefixSpaces(indentSpaces, $"(equivalent to '{CreateArgumentCommandsAnalyzerProvidersWithCollect()} {CreateArgumentProjectPathWithCurrentFolder()}')");
private static string PrefixSpaces(int indentSpaces, string value) => value.PadLeft(value.Length + indentSpaces);
}