2022-11-20 12:54:26 -08:00
|
|
|
const std = @import("std");
|
|
|
|
const noclip = @import("noclip");
|
|
|
|
|
2022-11-26 20:29:23 -08:00
|
|
|
const context: []const u8 = "hello friend";
|
|
|
|
const ContextType = @TypeOf(context);
|
2022-11-20 12:54:26 -08:00
|
|
|
|
2022-11-27 01:31:20 -08:00
|
|
|
const subcommand = blk: {
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
var cmd = noclip.Command(ContextType, .{ .name = "verb", .help = "this a sub command" });
|
2022-11-27 01:31:20 -08:00
|
|
|
cmd.add(cmd.defaultHelpFlag);
|
|
|
|
cmd.add(cmd.StringOption{ .name = "meta", .short = "-m" });
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
cmd.add(cmd.StringArgument{ .name = "argument" });
|
|
|
|
cmd.add(cmd.Argument(u32){ .name = "another", .default = 0 });
|
2022-11-27 01:31:20 -08:00
|
|
|
break :blk cmd;
|
|
|
|
};
|
2022-11-26 20:29:23 -08:00
|
|
|
|
2022-11-27 01:31:20 -08:00
|
|
|
const command = blk: {
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
var cmd = noclip.Command(ContextType, .{
|
|
|
|
.name = "main",
|
|
|
|
.help =
|
|
|
|
\\This is the main CLI entry point for the noclip demo
|
|
|
|
\\
|
|
|
|
\\This program demonstrates the major features of noclip both in terms of API
|
|
|
|
\\usage (in its source code) and argument parsing (in its execution).
|
|
|
|
,
|
|
|
|
});
|
|
|
|
cmd.add(cmd.defaultHelpFlag);
|
2022-11-27 01:31:20 -08:00
|
|
|
cmd.add(cmd.Flag{ .name = "flag", .truthy = .{ .short = "-f", .long = "--flag" }, .falsy = .{ .long = "--no-flag" } });
|
|
|
|
cmd.add(cmd.StringOption{
|
|
|
|
.name = "input",
|
|
|
|
.short = "-i",
|
|
|
|
.long = "--input",
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
.help = "some generic input",
|
|
|
|
.default = "in",
|
2022-11-27 01:31:20 -08:00
|
|
|
.envVar = "OPTS_INPUT",
|
|
|
|
});
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
cmd.add(cmd.StringOption{
|
|
|
|
.name = "output",
|
|
|
|
.long = "--output",
|
|
|
|
.default = "waoh",
|
|
|
|
.help = "name of the output",
|
|
|
|
});
|
|
|
|
cmd.add(cmd.Option(i32){
|
|
|
|
.name = "number",
|
|
|
|
.short = "-n",
|
|
|
|
.long = "--number",
|
|
|
|
.help = "a number",
|
|
|
|
.default = 0,
|
|
|
|
});
|
2022-11-26 20:29:23 -08:00
|
|
|
|
2022-11-27 01:31:20 -08:00
|
|
|
cmd.add(subcommand.Parser(subCallback));
|
|
|
|
break :blk cmd;
|
2022-11-20 12:54:26 -08:00
|
|
|
};
|
|
|
|
|
2022-11-27 01:31:20 -08:00
|
|
|
fn printHandler(ctx: ContextType, input: []const u8) ![]const u8 {
|
|
|
|
std.debug.print("ctx: {s}\n", .{ctx});
|
|
|
|
return input;
|
|
|
|
}
|
2022-11-20 12:54:26 -08:00
|
|
|
|
2022-11-27 01:31:20 -08:00
|
|
|
pub fn subCallback(_: ContextType, result: subcommand.CommandResult()) !void {
|
|
|
|
std.debug.print(
|
|
|
|
\\subcommand: {{
|
|
|
|
\\ .meta = {s}
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
\\ .argument = {s}
|
|
|
|
\\ .another = {d}
|
2022-11-27 01:31:20 -08:00
|
|
|
\\}}
|
|
|
|
\\
|
|
|
|
,
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
.{ result.meta, result.argument, result.another },
|
2022-11-27 01:31:20 -08:00
|
|
|
);
|
2022-11-20 12:54:26 -08:00
|
|
|
}
|
|
|
|
|
2022-11-27 01:31:20 -08:00
|
|
|
pub fn mainCommand(_: ContextType, result: command.CommandResult()) !void {
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
// std.debug.print("{any}", .{result});
|
2022-11-20 12:54:26 -08:00
|
|
|
std.debug.print(
|
|
|
|
\\arguments: {{
|
2022-11-26 20:29:23 -08:00
|
|
|
\\ .flag = {any}
|
2022-11-20 12:54:26 -08:00
|
|
|
\\ .input = {s}
|
|
|
|
\\ .output = {s}
|
|
|
|
\\ .number = {d}
|
|
|
|
\\}}
|
|
|
|
\\
|
|
|
|
,
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
.{ result.flag, result.input, result.output, result.number },
|
2022-11-20 12:54:26 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() !void {
|
2022-11-27 01:31:20 -08:00
|
|
|
var parser = command.Parser(mainCommand);
|
2022-11-20 12:54:26 -08:00
|
|
|
|
|
|
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
|
|
|
defer arena.deinit();
|
|
|
|
|
|
|
|
const allocator = arena.allocator();
|
|
|
|
var argit = try std.process.argsWithAllocator(allocator);
|
|
|
|
|
2022-11-27 01:31:20 -08:00
|
|
|
try parser.execute(allocator, std.process.ArgIterator, &argit, context);
|
2022-11-20 12:54:26 -08:00
|
|
|
}
|