refactor(commands): add a substitute constructor
This commit recuces some repetitiveness from creating substitution literals in tests.
This commit is contained in:
parent
a05229f72d
commit
b0f0daa19d
2 changed files with 12 additions and 14 deletions
|
|
@ -9,6 +9,15 @@ pub const UserCommand = union(enum) {
|
|||
/// !help
|
||||
help: void,
|
||||
|
||||
pub fn init_substitute(author: []const u8, needle: []const u8, replacement: []const u8, all: bool) UserCommand {
|
||||
return .{ .substitute = .{
|
||||
.author = author,
|
||||
.needle = needle,
|
||||
.replacement = replacement,
|
||||
.all = all,
|
||||
} };
|
||||
}
|
||||
|
||||
pub fn parse(nick: []const u8, text: []const u8) ?UserCommand {
|
||||
const original = Parser.init(text);
|
||||
if (original.consume_str("!help")) |_| {
|
||||
|
|
@ -38,14 +47,7 @@ pub const UserCommand = union(enum) {
|
|||
return null;
|
||||
}
|
||||
parser, const correction = result.?;
|
||||
return .{
|
||||
.substitute = .{
|
||||
.author = nick,
|
||||
.needle = typo,
|
||||
.replacement = correction,
|
||||
.all = false,
|
||||
},
|
||||
};
|
||||
return .init_substitute(nick, typo, correction, false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue