Skip to content

Commit 27a72a5

Browse files
committed
fix(): Review Compliance
1 parent 2662d7a commit 27a72a5

File tree

6 files changed

+48
-43
lines changed

6 files changed

+48
-43
lines changed

packages/mcl/src/main.d

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import std.stdio : writefln, writeln, stderr;
44
import std.array : replace;
55
import std.getopt : getopt;
66
import std.logger : infof, errorf, LogLevel;
7-
import std.sumtype : SumType, match;
87
import std.string : stripRight, stripLeft;
98
import std.algorithm : endsWith;
109
import std.format : format;
@@ -28,7 +27,7 @@ int unknown_command(UnknownCommandArgs unused)
2827
struct MCLArgs
2928
{
3029
@NamedArgument(["log-level"])
31-
LogLevel logLevel = cast(LogLevel)-1;
30+
LogLevel logLevel = LogLevel.info;
3231

3332
SubCommand!(
3433
staticMap!(Parameters, SubCommandFunctions),
@@ -40,16 +39,13 @@ alias SumTypeCase(alias func) = (Parameters!func args) => func(args);
4039

4140
mixin CLI!MCLArgs.main!((args)
4241
{
43-
LogLevel logLevel = LogLevel.info;
44-
if (args.logLevel != cast(LogLevel)-1)
45-
logLevel = args.logLevel;
46-
setLogLevel(logLevel);
42+
setLogLevel(args.logLevel);
4743

4844
int result = args.cmd.matchCmd!(
4945
staticMap!(SumTypeCase, unknown_command, SubCommandFunctions),
5046
);
5147

52-
return 0;
48+
return result;
5349
});
5450

5551
void setLogLevel(LogLevel l)

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,18 @@ mixin template CiMatrixBaseArgs()
151151

152152
@(NamedArgument(["flake-pre"])
153153
.Placeholder("prefix")
154+
.EnvFallback("FLAKE_PRE")
154155
)
155-
string flakePre = "checks";
156+
string _flakePre = "checks";
157+
158+
@property {
159+
string flakePre() => _flakePre == "" ? "checks" : _flakePre;
160+
void flakePre(string v) => cast(void)(_flakePre = v);
161+
}
156162

157163
@(NamedArgument(["flake-post"])
158164
.Placeholder("postfix")
165+
.EnvFallback("FLAKE_POST")
159166
)
160167
string flakePost;
161168

@@ -169,7 +176,9 @@ mixin template CiMatrixBaseArgs()
169176
)
170177
int maxMemory;
171178

172-
@(NamedArgument(["initial"])
179+
@(NamedArgument(["is-initial"])
180+
.Description("Is this the initial run of the CI?")
181+
.EnvFallback("IS_INITIAL")
173182
)
174183
bool isInitial;
175184

@@ -186,6 +195,12 @@ mixin template CiMatrixBaseArgs()
186195
.Required()
187196
)
188197
string cachixAuthToken;
198+
199+
@(NamedArgument(["precalc-matrix"])
200+
.Placeholder("matrix")
201+
.EnvFallback("PRECALC_MATRIX")
202+
)
203+
string precalcMatrix = "";
189204
}
190205

191206
@(Command("ci-matrix", "ci_matrix")
@@ -200,11 +215,6 @@ struct CiMatrixArgs
200215
struct PrintTableArgs
201216
{
202217
mixin CiMatrixBaseArgs!();
203-
204-
@(NamedArgument(["precalc-matrix"])
205-
.Placeholder("matrix")
206-
)
207-
string precalcMatrix;
208218
}
209219

210220
export int ci_matrix(CiMatrixArgs args)
@@ -696,11 +706,9 @@ unittest
696706
void printTableForCacheStatus(T)(Package[] packages, auto ref T args)
697707
if (is(T == CiMatrixArgs) || is(T == PrintTableArgs) || is(T == CiArgs) || is(T == DeploySpecArgs))
698708
{
699-
static if (is(T == PrintTableArgs)) {
700-
if (args.precalcMatrix == "")
701-
{
702-
saveGHCIMatrix(packages, args);
703-
}
709+
if (args.precalcMatrix == "")
710+
{
711+
saveGHCIMatrix(packages, args);
704712
}
705713
saveCachixDeploySpec(packages);
706714
saveGHCIComment(convertNixEvalToTableSummary(packages, args.isInitial));

packages/mcl/src/src/mcl/commands/config.d

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
module mcl.commands.config;
22

33
import std.algorithm : canFind;
4-
import std.array : array;
4+
import std.array : array, join;
55
import std.process : ProcessPipes, Redirect, wait, environment;
66
import std.range : drop, front;
77
import std.stdio : writeln;
88
import std.string : indexOf;
9+
import std.conv : to;
910

10-
import argparse : Command, Description, SubCommand, Default, PositionalArgument, Placeholder, Optional, matchCmd;
11+
import argparse : Command, Description, SubCommand, Default, PositionalArgument, Placeholder, Optional, matchCmd, NamedArgument, EnvFallback;
1112

1213
import mcl.utils.fetch : fetchJson;
1314
import mcl.utils.log : errorAndExit;
@@ -60,18 +61,23 @@ struct HomeArgs
6061
) cmd;
6162
}
6263

64+
enum HomeConfigType { desktop, server }
65+
6366
@(Command("apply").Description("Apply user configuration"))
6467
struct HomeApplyArgs
6568
{
6669
@(PositionalArgument(0).Placeholder("desktop/server").Description("Type of home configuration"))
67-
string type;
70+
HomeConfigType type;
71+
72+
@(NamedArgument(["user"]).Optional().Placeholder("username").Description("Username to apply the configuration for").EnvFallback("USER"))
73+
string user = "";
6874
}
6975

7076
@(Command("edit").Description("Edit user configuration"))
7177
struct HomeEditArgs
7278
{
7379
@(PositionalArgument(0).Placeholder("desktop/server").Description("Type of home configuration"))
74-
string type;
80+
HomeConfigType type;
7581
}
7682

7783
@(Command("start-vm").Description("Start a VM"))
@@ -143,17 +149,17 @@ int edit(string type, string path)
143149
}
144150
}
145151

146-
int apply(string type, string value)
152+
int apply(string type, string[] args)
147153
{
148-
writeln("Applying ", type, " configuration from: ", value);
149-
return executeCommand("just switch-" ~ type ~ " " ~ value);
154+
writeln("Applying ", type, " configuration from: ", args);
155+
return executeCommand("just switch-" ~ type ~ " " ~ args.join(" "));
150156
}
151157

152158
int sys(SysArgs args)
153159
{
154160
return args.cmd.matchCmd!(
155-
(SysApplyArgs a) => apply("system", a.machineName),
156-
(SysEditArgs a) => edit("system", a.machineName),
161+
(SysApplyArgs a) => "system".apply([a.machineName]),
162+
(SysEditArgs a) => "system".edit(a.machineName),
157163
(UnknownCommandArgs a) => unknown_command(a)
158164
);
159165
}
@@ -162,11 +168,8 @@ int home(HomeArgs args)
162168
{
163169

164170
return args.cmd.matchCmd!(
165-
(HomeApplyArgs a) {
166-
writeln("Applying home configuration from: ", a.type);
167-
return executeCommand("just switch-home " ~ a.type);
168-
},
169-
(HomeEditArgs a) => "user".edit(a.type),
171+
(HomeApplyArgs a) => "home".apply([a.type.to!string, a.user]),
172+
(HomeEditArgs a) => "user".edit(a.type.to!string),
170173
(UnknownCommandArgs a) => unknown_command(a)
171174
);
172175
}

packages/mcl/src/src/mcl/commands/deploy_spec.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export int deploy_spec(DeploySpecArgs args)
6060
infof("%s machines will be deployed.", spec.agents.length);
6161

6262
if (!spec.agents.length)
63-
return 1;
63+
return 0;
6464

6565
spawnProcessInline([
6666
"cachix", "deploy", "activate", deploySpecFile, "--async"

packages/mcl/src/src/mcl/commands/host_info.d

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ string[string] getProcInfo(string fileOrData, bool file = true)
5757
struct HostInfoArgs {
5858
@(NamedArgument(["coda-api-token"])
5959
.Placeholder("token")
60-
.EnvFallback("CODA_API_TOKEN")
61-
)
60+
.EnvFallback("CODA_API_TOKEN"))
6261
string codaApiToken;
62+
63+
@(NamedArgument(["upload-to-coda"])
64+
.Description("Upload the host info to Coda"))
65+
bool uploadToCoda = false;
6366
}
6467

6568
export int host_info(HostInfoArgs args)
@@ -72,7 +75,7 @@ export int host_info(HostInfoArgs args)
7275
.toPrettyString(JSONOptions.doNotEscapeSlashes)
7376
.writeln();
7477

75-
if (!args.codaApiToken) {
78+
if (args.uploadToCoda &&!args.codaApiToken) {
7679
writeln("No Coda API token specified -> not uploading");
7780
return 1;
7881
}
@@ -81,7 +84,7 @@ export int host_info(HostInfoArgs args)
8184
auto coda = CodaApiClient(args.codaApiToken);
8285
coda.uploadHostInfo(hostInfo);
8386

84-
return 1;
87+
return 0;
8588

8689
}
8790

packages/mcl/src/src/mcl/commands/machine.d

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ struct User {
3535

3636
struct UserInfo
3737
{
38-
bool isNormalUser;
3938
string description;
4039
string[] extraGroups;
4140
string hashedPassword;
@@ -59,7 +58,6 @@ User getUser(string userName)
5958
auto userJson = nix.eval!JSONValue("users/" ~ userName ~ "/user-info.nix", ["--file"]);
6059
User user;
6160
user.userName = userName;
62-
user.userInfo.isNormalUser = userJson["userInfo"]["isNormalUser"].boolean;
6361
user.userInfo.description = userJson["userInfo"]["description"].str;
6462
user.userInfo.extraGroups = userJson["userInfo"]["extraGroups"].array.map!(a => a.str).array;
6563
user.userInfo.hashedPassword = userJson["userInfo"]["hashedPassword"].str;
@@ -189,7 +187,6 @@ User createUser(CreateMachineArgs args) {
189187
User user;
190188
user.userName = args.userName != "" ? args.userName : prompt!string("Enter the new username");
191189
user.userInfo.description = args.description != "" ? args.description : prompt!string("Enter the user's description/full name");
192-
user.userInfo.isNormalUser = args.isNormalUser || prompt!bool("Is this a normal or root user");
193190
user.userInfo.extraGroups = (args.extraGroups != "" ? args.extraGroups : prompt!string("Enter the user's extra groups (comma delimited)", getGroups())).split(",").map!(strip).array;
194191
createUserDir(user);
195192
return user;
@@ -400,8 +397,6 @@ struct CreateMachineArgs
400397
string machineName;
401398
@(NamedArgument(["description"]).Placeholder("description").Description("Description of the user"))
402399
string description;
403-
@(NamedArgument(["is-normal-user"]).Placeholder("true/false").Description("Is this a normal user"))
404-
bool isNormalUser;
405400
@(NamedArgument(["extra-groups"]).Placeholder("group1,group2").Description("Extra groups for the user"))
406401
string extraGroups;
407402
@(NamedArgument(["machine-type"]).Placeholder("desktop/server/container").Description("Type of machine"))

0 commit comments

Comments
 (0)