@@ -6,47 +6,54 @@ import std.json : JSONValue;
66import std.format : fmt = format;
77import std.exception : enforce;
88
9+ import argparse;
10+
911import mcl.utils.cachix : cachixNixStoreUrl, getCachixDeploymentApiUrl;
1012import mcl.utils.env : optional, parseEnv;
1113import mcl.utils.fetch : fetchJson;
1214import mcl.utils.nix : queryStorePath, nix;
1315import mcl.utils.string : camelCaseToCapitalCase;
1416import 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}
0 commit comments