Skip to content

Commit c5a2fff

Browse files
committed
feat(commands/host_info): Enhance host_info command with argparse integration and structured argument handling
1 parent c9faffb commit c5a2fff

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

packages/mcl/src/main.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ template genSubCommandArgs()
3131
"SumType!("~
3232
"get_fstab_args,"~
3333
"deploy_spec_args,"~
34+
"host_info_args,"~
3435
"Default!unknown_command_args"~
3536
") cmd;";
3637
}

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

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,15 @@ import std.json;
1616
import std.process : ProcessPipes, environment;
1717
import core.stdc.string: strlen;
1818

19+
import argparse;
20+
1921
import mcl.utils.env : parseEnv, optional;
2022
import mcl.utils.json : toJSON;
2123
import mcl.utils.process : execute, isRoot;
2224
import mcl.utils.number : humanReadableSize;
2325
import mcl.utils.array : uniqIfSame;
2426
import mcl.utils.nix : Literal;
2527

26-
// enum InfoFormat
27-
// {
28-
// JSON,
29-
// CSV,
30-
// TSV
31-
// }
32-
33-
struct Params
34-
{
35-
// @optional()
36-
// InfoFormat format = InfoFormat.JSON;
37-
void setup()
38-
{
39-
}
40-
}
41-
4228
string[string] cpuinfo;
4329

4430
string[string] meminfo;
@@ -62,14 +48,17 @@ string[string] getProcInfo(string fileOrData, bool file = true)
6248
return r;
6349
}
6450

65-
export void host_info(string[] args)
66-
{
67-
const params = parseEnv!Params;
51+
@(Command("host-info").Description("Get information about the host machine"))
52+
struct host_info_args {}
6853

54+
export int host_info(host_info_args args)
55+
{
6956
Info info = getInfo();
7057

7158
writeln(info.toJSON(true).toPrettyString(JSONOptions.doNotEscapeSlashes));
7259

60+
return 1;
61+
7362
}
7463

7564
Info getInfo()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ public import mcl.commands.deploy_spec : deploy_spec, deploy_spec_args;
55
public import mcl.commands.ci_matrix : ci_matrix, print_table;
66
public import mcl.commands.shard_matrix : shard_matrix;
77
public import mcl.commands.ci : ci;
8-
public import mcl.commands.host_info : host_info;
8+
public import mcl.commands.host_info : host_info, host_info_args;
99
public import mcl.commands.machine : machine;
1010
public import mcl.commands.config : config;

0 commit comments

Comments
 (0)