-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathe4_custom_sections.zig
More file actions
71 lines (61 loc) · 2.11 KB
/
e4_custom_sections.zig
File metadata and controls
71 lines (61 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const std = @import("std");
const chilli = @import("chilli");
fn dummyExec(ctx: chilli.CommandContext) !void {
try ctx.command.printHelp();
}
pub fn main(init: std.process.Init.Minimal) anyerror!void {
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var root_cmd = try chilli.Command.init(allocator, .{
.name = "section-demo",
.description = "Demonstrates custom subcommand sections.",
.exec = dummyExec,
});
defer root_cmd.deinit();
const cmd_get = try chilli.Command.init(allocator, .{
.name = "get",
.description = "Get a resource.",
.exec = dummyExec,
.section = "Core Commands",
});
try root_cmd.addSubcommand(cmd_get);
const cmd_set = try chilli.Command.init(allocator, .{
.name = "set",
.description = "Set a resource.",
.exec = dummyExec,
.section = "Core Commands",
});
try root_cmd.addSubcommand(cmd_set);
const cmd_config = try chilli.Command.init(allocator, .{
.name = "config",
.description = "Configure the application.",
.exec = dummyExec,
.section = "Management Commands",
});
try root_cmd.addSubcommand(cmd_config);
const cmd_auth = try chilli.Command.init(allocator, .{
.name = "auth",
.description = "Authenticate with the service.",
.exec = dummyExec,
.section = "Management Commands",
});
try root_cmd.addSubcommand(cmd_auth);
const cmd_other = try chilli.Command.init(allocator, .{
.name = "other",
.description = "Another command.",
.exec = dummyExec,
});
try root_cmd.addSubcommand(cmd_other);
try root_cmd.run(init.args, null);
}
// Example Invocation
//
// This example's main purpose is to demonstrate the custom section titles in the
// help output. The root command is configured to print its help message by default.
//
// You can see the formatted output by running:
// zig build run-e4_custom_sections
//
// Or, to invoke help explicitly:
// ./zig-out/bin/e4_custom_sections --help