Skip to content

Commit 9ee2900

Browse files
committed
feat(commands/get_fstab): Enhance get_fstab command with argparse integration and structured argument handling
1 parent ee671fd commit 9ee2900

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

packages/mcl/src/main.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ template genSubCommandArgs()
2929
const char[] genSubCommandArgs =
3030
"@SubCommands\n"~
3131
"SumType!("~
32+
"get_fstab_args,"~
3233
"Default!unknown_command_args"~
3334
") cmd;";
3435
}

packages/mcl/src/src/mcl/commands/get_fstab.d

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,54 @@ import std.json : JSONValue;
66
import std.format : fmt = format;
77
import std.exception : enforce;
88

9+
import argparse;
10+
911
import mcl.utils.cachix : cachixNixStoreUrl, getCachixDeploymentApiUrl;
1012
import mcl.utils.env : optional, parseEnv;
1113
import mcl.utils.fetch : fetchJson;
1214
import mcl.utils.nix : queryStorePath, nix;
1315
import mcl.utils.string : camelCaseToCapitalCase;
1416
import mcl.utils.process : execute;
1517

16-
export void get_fstab(string[] args)
18+
export int get_fstab(get_fstab_args args)
1719
{
18-
const params = parseEnv!Params;
19-
const machineStorePath = getCachixDeploymentStorePath(params);
20+
args.cachixStoreUrl = cachixNixStoreUrl(args.cachixCache);
21+
if (!args.cachixDeployWorkspace)
22+
args.cachixDeployWorkspace = args.cachixCache;
23+
24+
const machineStorePath = getCachixDeploymentStorePath(args);
2025
const fstabStorePath = queryStorePath(
2126
machineStorePath,
2227
["-etc", "-etc-fstab"],
23-
params.cachixStoreUrl
28+
args.cachixStoreUrl
2429
);
2530
nix.build(fstabStorePath);
2631
writeln(fstabStorePath);
32+
return 0;
2733
}
2834

29-
struct Params
30-
{
35+
@(Command("get-fstab").Description("Get the store path of the fstab file for a deployment"))
36+
export struct get_fstab_args {
37+
@(NamedArgument(["cachix-auth-token"]).Required().Placeholder("XXX").Description("Auth Token for Cachix"))
3138
string cachixAuthToken;
39+
@(NamedArgument(["cachix-cache"]).Required().Placeholder("cache").Description("Which Cachix cache to use"))
3240
string cachixCache;
33-
@optional() string cachixStoreUrl;
34-
@optional() string cachixDeployWorkspace;
35-
string machineName;
36-
uint deploymentId;
3741

38-
void setup()
39-
{
42+
@(NamedArgument(["cachix-store-url"]).Placeholder("https://...").Description("URL of the Cachix store"))
43+
string cachixStoreUrl = "";
44+
@(NamedArgument(["cachix-deploy-workspace"]).Placeholder("agent-workspace").Description("Cachix workspace to deploy to"))
45+
string cachixDeployWorkspace = "";
4046

41-
cachixStoreUrl = cachixNixStoreUrl(cachixCache);
42-
if (!cachixDeployWorkspace)
43-
cachixDeployWorkspace = cachixCache;
44-
}
47+
@(PositionalArgument(0).Placeholder("machine-name").Description("Name of the machine"))
48+
string machineName;
49+
@(PositionalArgument(1).Placeholder("deployment-id").Description("ID of the deployment"))
50+
uint deploymentId;
4551
}
4652

47-
string getCachixDeploymentStorePath(Params p)
53+
54+
string getCachixDeploymentStorePath(get_fstab_args args)
4855
{
49-
const url = getCachixDeploymentApiUrl(p.cachixDeployWorkspace, p.machineName, p.deploymentId);
50-
const response = fetchJson(url, p.cachixAuthToken);
56+
const url = getCachixDeploymentApiUrl(args.cachixDeployWorkspace, args.machineName, args.deploymentId);
57+
const response = fetchJson(url, args.cachixAuthToken);
5158
return response["storePath"].get!string;
5259
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module mcl.commands;
22

3-
public import mcl.commands.get_fstab : get_fstab;
3+
public import mcl.commands.get_fstab : get_fstab, get_fstab_args;
44
public import mcl.commands.deploy_spec : deploy_spec;
55
public import mcl.commands.ci_matrix : ci_matrix, print_table;
66
public import mcl.commands.shard_matrix : shard_matrix;

0 commit comments

Comments
 (0)