Compare commits
No commits in common. "70c6cea59112f90c9732f97abe11c1de8bf5598e" and "35915191fba37d0bc161cc586e2a4aeb70e6a14c" have entirely different histories.
70c6cea591
...
35915191fb
@ -11,19 +11,6 @@ const cli = cmd: {
|
|||||||
\\The definitive noclip demonstration utility
|
\\The definitive noclip demonstration utility
|
||||||
\\
|
\\
|
||||||
\\This command demonstrates the functionality of the noclip library. cool!
|
\\This command demonstrates the functionality of the noclip library. cool!
|
||||||
\\
|
|
||||||
\\> // implementing factorial recursively is a silly thing to do
|
|
||||||
\\> pub fn fact(n: u64) u64 {
|
|
||||||
\\> if (n == 0) return 1;
|
|
||||||
\\> return n*fact(n - 1);
|
|
||||||
\\> }
|
|
||||||
\\
|
|
||||||
\\Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
|
||||||
\\incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
|
|
||||||
\\nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
|
||||||
\\Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
|
|
||||||
\\eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
|
|
||||||
\\sunt in culpa qui officia deserunt mollit anim id est laborum.
|
|
||||||
,
|
,
|
||||||
};
|
};
|
||||||
cmd.addOption(.{ .OutputType = struct { u8, u8 } }, .{
|
cmd.addOption(.{ .OutputType = struct { u8, u8 } }, .{
|
||||||
|
@ -167,7 +167,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
|
|||||||
return Parser(self, callback){
|
return Parser(self, callback){
|
||||||
.arena = arena,
|
.arena = arena,
|
||||||
.allocator = arena_alloc,
|
.allocator = arena_alloc,
|
||||||
.subcommands = parser.CommandMap.init(arena_alloc),
|
.subcommands = std.hash_map.StringHashMap(ParserInterface).init(arena_alloc),
|
||||||
.help_builder = help.HelpBuilder(self).init(arena_alloc),
|
.help_builder = help.HelpBuilder(self).init(arena_alloc),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ pub fn CommandBuilder(comptime UserContext: type) type {
|
|||||||
this_parser.* = .{
|
this_parser.* = .{
|
||||||
.arena = arena,
|
.arena = arena,
|
||||||
.allocator = arena_alloc,
|
.allocator = arena_alloc,
|
||||||
.subcommands = parser.CommandMap.init(arena_alloc),
|
.subcommands = std.hash_map.StringHashMap(ParserInterface).init(arena_alloc),
|
||||||
.help_builder = help.HelpBuilder(self).init(arena_alloc),
|
.help_builder = help.HelpBuilder(self).init(arena_alloc),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,17 +65,6 @@ pub fn StructuredPrinter(comptime Writer: type) type {
|
|||||||
// we have a trailing line that needs to be cleaned up
|
// we have a trailing line that needs to be cleaned up
|
||||||
if (location > indent)
|
if (location > indent)
|
||||||
_ = try self.clearLine(indent);
|
_ = try self.clearLine(indent);
|
||||||
|
|
||||||
location = try self.clearLine(indent);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line[0] == '>') maybe: {
|
|
||||||
if (line.len > 1) {
|
|
||||||
if (line[1] == ' ') {
|
|
||||||
try self.writer.writeAll(line[2..]);
|
|
||||||
} else break :maybe;
|
|
||||||
}
|
|
||||||
location = try self.clearLine(indent);
|
location = try self.clearLine(indent);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -112,7 +101,6 @@ pub fn StructuredPrinter(comptime Writer: type) type {
|
|||||||
}
|
}
|
||||||
if (location > indent)
|
if (location > indent)
|
||||||
try self.writer.writeByte(' ');
|
try self.writer.writeByte(' ');
|
||||||
|
|
||||||
try self.writer.writeAll(choppee[0..split]);
|
try self.writer.writeAll(choppee[0..split]);
|
||||||
location = try self.clearLine(indent);
|
location = try self.clearLine(indent);
|
||||||
choppee = choppee[split + 1 ..];
|
choppee = choppee[split + 1 ..];
|
||||||
@ -360,10 +348,11 @@ pub fn HelpBuilder(comptime command: anytype) type {
|
|||||||
defer pairs.deinit();
|
defer pairs.deinit();
|
||||||
|
|
||||||
var just: usize = 0;
|
var just: usize = 0;
|
||||||
for (subcommands.keys()) |key| {
|
var iter = subcommands.keyIterator();
|
||||||
|
while (iter.next()) |key| {
|
||||||
const pair: AlignablePair = .{
|
const pair: AlignablePair = .{
|
||||||
.left = key,
|
.left = key.*,
|
||||||
.right = subcommands.get(key).?.describe(),
|
.right = subcommands.get(key.*).?.describe(),
|
||||||
};
|
};
|
||||||
if (pair.left.len > just) just = pair.left.len;
|
if (pair.left.len > just) just = pair.left.len;
|
||||||
try pairs.append(pair);
|
try pairs.append(pair);
|
||||||
|
@ -73,7 +73,7 @@ pub const ParserInterface = struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const CommandMap = std.StringArrayHashMap(ParserInterface);
|
pub const CommandMap = std.hash_map.StringHashMap(ParserInterface);
|
||||||
|
|
||||||
// the parser is generated by the bind method of the CommandBuilder, so we can
|
// the parser is generated by the bind method of the CommandBuilder, so we can
|
||||||
// be extremely type-sloppy here, which simplifies the signature.
|
// be extremely type-sloppy here, which simplifies the signature.
|
||||||
@ -144,7 +144,8 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinitTree(self: @This()) void {
|
pub fn deinitTree(self: @This()) void {
|
||||||
for (self.subcommands.values()) |subcommand| {
|
var iterator = self.subcommands.valueIterator();
|
||||||
|
while (iterator.next()) |subcommand| {
|
||||||
subcommand.deinitTree();
|
subcommand.deinitTree();
|
||||||
}
|
}
|
||||||
self.deinit();
|
self.deinit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user