Skip to content

Commit 452bda9

Browse files
committed
Add --only commandline arg to silktouch
-also support for csv lists in --only and --skip
1 parent ed1c763 commit 452bda9

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

sources/SilkTouch/SilkTouch/Program.cs

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@
1717
var skip = new Option<string[]>(
1818
new[] { "--skip", "-s" },
1919
Array.Empty<string>,
20-
"A list of job names to skip."
20+
"A list of job names to skip. Takes precendence over --only."
2121
)
2222
{
2323
Arity = ArgumentArity.ZeroOrMore
2424
};
25+
var only = new Option<string[]>(
26+
new[] { "--only", "-o" },
27+
Array.Empty<string>,
28+
"A list of job names to run."
29+
) {
30+
Arity = ArgumentArity.ZeroOrMore
31+
};
2532
var configs = new Argument<string[]>("configs", "Path(s) to JSON SilkTouch configuration(s)")
2633
{
2734
Arity = ArgumentArity.OneOrMore
@@ -39,9 +46,8 @@
3946
() => Environment.ProcessorCount,
4047
"Maximum number of parallel ClangSharp executions."
4148
);
42-
var rootCommand = new RootCommand { logging, skip, configs, configOverrides, jobs };
43-
rootCommand.SetHandler(async ctx =>
44-
{
49+
var rootCommand = new RootCommand { logging, skip, only, configs, configOverrides, jobs };
50+
rootCommand.SetHandler(async ctx => {
4551
// Create the ConfigurationBuilder with support for env var & command line overrides
4652
var cb = new ConfigurationBuilder()
4753
.AddEnvironmentVariables(source => source.Prefix = "SILKDOTNET_")
@@ -63,10 +69,8 @@
6369
MSBuildLocator.RegisterDefaults();
6470

6571
var sp = new ServiceCollection()
66-
.AddLogging(builder =>
67-
{
68-
builder.AddSimpleConsole(opts =>
69-
{
72+
.AddLogging(builder => {
73+
builder.AddSimpleConsole(opts => {
7074
opts.SingleLine = true;
7175
opts.ColorBehavior = Console.IsOutputRedirected
7276
? LoggerColorBehavior.Disabled
@@ -80,17 +84,20 @@
8084
.BuildServiceProvider();
8185

8286
var logger = sp.GetRequiredService<ILogger<Program>>();
83-
var skipped = ctx.ParseResult.GetValueForOption(skip);
87+
var skipped = SeparateCSV(ctx.ParseResult.GetValueForOption(skip));
88+
var jobsToRun = SeparateCSV(ctx.ParseResult.GetValueForOption(only));
89+
8490
var generator = sp.GetRequiredService<SilkTouchGenerator>();
91+
8592
await Parallel.ForEachAsync(
8693
config
8794
.GetSection("Jobs")
8895
.GetChildren()
8996
.Where(x =>
90-
skipped?.All(y => !x.Key.Equals(y, StringComparison.OrdinalIgnoreCase)) ?? true
97+
(skipped?.All(y => !x.Key.Equals(y, StringComparison.OrdinalIgnoreCase)) ?? true) &&
98+
(jobsToRun is null || jobsToRun.Count == 0 || jobsToRun.Any(y => x.Key.Equals(y, StringComparison.OrdinalIgnoreCase)))
9199
),
92-
async (job, ct) =>
93-
{
100+
async (job, ct) => {
94101
await generator.RunAsync(
95102
job.Key,
96103
job,
@@ -105,3 +112,23 @@ await generator.RunAsync(
105112
});
106113

107114
await rootCommand.InvokeAsync(args);
115+
116+
static List<string> SeparateCSV(Span<string> strs)
117+
{
118+
if (strs.Length == 0)
119+
return [];
120+
121+
List<string> result = [];
122+
foreach (string str in strs)
123+
{
124+
if (str.Contains(','))
125+
{
126+
result.AddRange(str.Split(','));
127+
}
128+
else
129+
{
130+
result.Add(str);
131+
}
132+
}
133+
return result;
134+
}

0 commit comments

Comments
 (0)