Skip to content

Commit 79f2294

Browse files
committed
feat(commands): Enhance ci/matrix commands with argparse integration and structured argument handling where applicable
1 parent cd9c94c commit 79f2294

File tree

5 files changed

+44
-20
lines changed

5 files changed

+44
-20
lines changed

packages/mcl/src/main.d

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ template genSubCommandArgs()
3434
"host_info_args,"~
3535
"config_args,"~
3636
"machine_args,"~
37+
"ci_matrix_args,"~
38+
"ci_args,"~
39+
"print_table_args,"~
40+
"shard_matrix_args,"~
3741
"Default!unknown_command_args"~
3842
") cmd;";
3943
}
@@ -74,7 +78,7 @@ mixin CLI!MCLArgs.main!((args)
7478

7579
mixin genSubCommandMatch;
7680

77-
return 0;
81+
return 0;
7882
});
7983

8084
void setLogLevel(LogLevel l)

packages/mcl/src/src/mcl/commands/ci.d

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import std.array : array, join;
88
import std.conv : to;
99
import std.process : ProcessPipes;
1010

11+
import argparse;
12+
1113
import mcl.utils.env : optional, parseEnv;
1214
import mcl.commands.ci_matrix: nixEvalJobs, SupportedSystem, Params, flakeAttr;
1315
import mcl.commands.shard_matrix: generateShardMatrix;
@@ -18,6 +20,11 @@ import mcl.utils.json : toJSON;
1820

1921
Params params;
2022

23+
@(Command("ci").Description("Run CI"))
24+
struct ci_args
25+
{
26+
}
27+
2128
export void ci(string[] args)
2229
{
2330
params = parseEnv!Params;

packages/mcl/src/src/mcl/commands/ci_matrix.d

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import std.exception : enforce;
1616
import std.format : fmt = format;
1717
import std.logger : tracef, infof, errorf, warningf;
1818

19+
import argparse;
20+
1921
import mcl.utils.env : optional, MissingEnvVarsException, parseEnv;
2022
import mcl.utils.string : enumToString, StringRepresentation, MaxWidth, writeRecordAsTable;
2123
import mcl.utils.json : toJSON;
@@ -143,8 +145,11 @@ version (unittest)
143145

144146
Params params;
145147

146-
147-
export void ci_matrix(string[] args)
148+
@(Command("ci-matrix").Description("Print a table of the cache status of each package"))
149+
struct ci_matrix_args
150+
{
151+
}
152+
export void ci_matrix(ci_matrix_args args)
148153
{
149154
params = parseEnv!Params;
150155
createResultDirs();
@@ -182,13 +187,20 @@ Package[] checkCacheStatus(Package[] packages)
182187
return packages;
183188
}
184189

185-
export void print_table(string[] args)
190+
@(Command("print-table").Description("Print a table of the cache status of each package"))
191+
struct print_table_args
192+
{
193+
}
194+
195+
export int print_table(print_table_args args)
186196
{
187197
createResultDirs();
188198

189199
getPrecalcMatrix()
190200
.checkCacheStatus()
191201
.printTableForCacheStatus();
202+
203+
return 0;
192204
}
193205

194206
struct Params
@@ -199,6 +211,7 @@ struct Params
199211
@optional() int maxWorkers;
200212
@optional() int maxMemory;
201213
@optional() bool isInitial;
214+
202215
string cachixCache;
203216
string cachixAuthToken;
204217

packages/mcl/src/src/mcl/commands/package.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ module mcl.commands;
22

33
public import mcl.commands.get_fstab : get_fstab, get_fstab_args;
44
public import mcl.commands.deploy_spec : deploy_spec, deploy_spec_args;
5-
public import mcl.commands.ci_matrix : ci_matrix, print_table;
6-
public import mcl.commands.shard_matrix : shard_matrix;
7-
public import mcl.commands.ci : ci;
5+
public import mcl.commands.ci_matrix : ci_matrix,ci_matrix_args, print_table,print_table_args;
6+
public import mcl.commands.shard_matrix : shard_matrix, shard_matrix_args;
7+
public import mcl.commands.ci : ci, ci_args;
88
public import mcl.commands.host_info : host_info, host_info_args;
99
public import mcl.commands.machine : machine, machine_args;
1010
public import mcl.commands.config : config, config_args;

packages/mcl/src/src/mcl/commands/shard_matrix.d

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ import std.regex : matchFirst, regex;
1313
import std.stdio : writeln;
1414
import std.string : strip;
1515

16+
import argparse;
17+
1618
import mcl.utils.env : parseEnv, optional;
1719
import mcl.utils.json : toJSON;
1820
import mcl.utils.nix : nix;
1921
import mcl.utils.path : createResultDirs, resultDir, rootDir;
2022

21-
export void shard_matrix(string[] args)
23+
@(Command("shard-matrix").Description("Generate a shard matrix for a flake"))
24+
struct shard_matrix_args
2225
{
23-
const params = parseEnv!Params;
24-
auto matrix = generateShardMatrix();
25-
saveShardMatrix(matrix, params);
26-
26+
@(NamedArgument(["github-output"]).Placeholder("output").Description("Output to GitHub Actions"))
27+
string githubOutput;
2728
}
2829

29-
struct Params
30+
export int shard_matrix(shard_matrix_args args)
3031
{
31-
@optional() string githubOutput;
32+
auto matrix = generateShardMatrix();
33+
saveShardMatrix(matrix, args);
34+
return 0;
3235

33-
void setup()
34-
{
35-
}
3636
}
3737

3838
struct Shard
@@ -138,15 +138,15 @@ unittest
138138

139139
}
140140

141-
void saveShardMatrix(ShardMatrix matrix, Params params)
141+
void saveShardMatrix(ShardMatrix matrix, shard_matrix_args args)
142142
{
143143
const matrixJson = matrix.toJSON();
144144
const matrixString = matrixJson.toString();
145145
infof("Shard matrix: %s", matrixJson.toPrettyString);
146146
const envLine = "gen_matrix=" ~ matrixString;
147-
if (params.githubOutput != "")
147+
if (args.githubOutput != "")
148148
{
149-
params.githubOutput.append(envLine);
149+
args.githubOutput.append(envLine);
150150
}
151151
else
152152
{

0 commit comments

Comments
 (0)