cli: remove aliases and shortcuts

This commit is contained in:
Halil Durak
2026-04-17 17:33:54 +03:00
parent a3af914cda
commit 012fe40bb5
2 changed files with 8 additions and 31 deletions

View File

@@ -101,8 +101,8 @@ const Commands = cli.Builder(.{
.{
.name = "serve",
.options = .{
.{ .name = "host", .shortcuts = .{ "h", "H" }, .type = []const u8, .default = "127.0.0.1" },
.{ .name = "port", .shortcuts = .{ "p", "P" }, .type = u16, .default = 9222 },
.{ .name = "host", .type = []const u8, .default = "127.0.0.1" },
.{ .name = "port", .type = u16, .default = 9222 },
.{ .name = "advertise_host", .type = ?[]const u8 },
.{ .name = "timeout", .type = u31, .default = 10 },
.{ .name = "cdp_max_connections", .type = u16, .default = 16 },
@@ -112,11 +112,10 @@ const Commands = cli.Builder(.{
},
.{
.name = "fetch",
.aliases = .{ "f", "get" },
// This argument can be given out of order.
.positional = .{ .name = "url", .type = ?[:0]const u8 },
.options = .{
.{ .name = "dump", .shortcuts = .{ "d", "D" }, .type = ?DumpFormat, .validator = dumpValidator },
.{ .name = "dump", .type = ?DumpFormat, .validator = dumpValidator },
.{ .name = "with_base", .type = bool },
.{ .name = "with_frames", .type = bool },
.{ .name = "strip", .type = dump.Opts.Strip, .default = dump.Opts.Strip{} },
@@ -134,8 +133,8 @@ const Commands = cli.Builder(.{
},
.shared_options = CommonOptions,
},
.{ .name = "version", .aliases = .{"v"}, .options = .{} },
.{ .name = "help", .aliases = .{ "h", "?" }, .options = .{} },
.{ .name = "version", .options = .{} },
.{ .name = "help", .options = .{} },
});
pub const RunMode = Commands.Enum;

View File

@@ -263,19 +263,9 @@ pub fn Builder(comptime commands: anytype) type {
const cmd_str: []const u8 = args.next() orelse return error.MissingCommand;
inline for (commands) |command| {
// Command name together with it's aliases.
const with_aliases = blk: {
if (@hasField(@TypeOf(command), "aliases")) {
break :blk command.aliases ++ .{command.name};
}
break :blk .{command.name};
};
inline for (with_aliases) |name| {
if (std.mem.eql(u8, cmd_str, name)) {
return .{ exec_name, try parseCommand(allocator, command, &args) };
}
// Match a command.
if (std.mem.eql(u8, cmd_str, command.name)) {
return .{ exec_name, try parseCommand(allocator, command, &args) };
}
}
@@ -369,18 +359,6 @@ pub fn Builder(comptime commands: anytype) type {
const match =
std.mem.eql(u8, option_name, "--" ++ option.name) or
std.mem.eql(u8, option_name, "--" ++ kebab_cased);
// Name not matched; try shortcuts if provided.
if (!match) {
if (@hasField(@TypeOf(option), "shortcuts")) {
inline for (option.shortcuts) |shortcut| {
if (std.mem.eql(u8, option_name, "-" ++ shortcut)) {
break :blk true;
}
}
}
}
break :blk match;
};