A library for creating text-chat commands that can receive strongly-typed argument data
| src | ||
| .gitignore | ||
| eslint.config.ts | ||
| LICENCE.md | ||
| package.json | ||
| pnpm-lock.yaml | ||
| README.md | ||
| tsconfig.json | ||
| tsup.config.ts | ||
Text-chat Commands
This is a library for use in environments where text commands are being parsed. This is not made for CLIs but is designed for environments where a chat feature can optionally be used to invoke commands. GNU-style argument parsers are not generally the intended use of this library.
Specification
There are 5 types of argument types: literal, word, numeric, repeated, and remainder.
literalwill match a single token that exactly matches a given input,wordwill match any one token,numericwill match any stringified, base-10 number and can be specified to only match integers,repeatedwill match the same argument repeated zero or numerous times,remainderwill match any remaining tokens and treat them as one space-demarcated token.
Examples
const exampleCommand = tcc.makeCommandBuilder("example").then(
{ id: "first", type: "literal", "data": { "literal": "normal" } },
(builder) => {
return builder.then(
{ id: "value", type: "numeric" },
(builder) => {
return builder.executes(
(arg) => {
console.log("normal subcommand triggered, numeric value:", arg.value);
}
).build();
}
).build();
}
).orThen(
{ id: "first", type: "literal", "data": { "literal": "alternative" } },
(builder) => builder.executes(
(unused) => {
console.log("alternative subcommand triggered");
}
).build()
).build();
exampleCommand can process inputs of the format:
example normal <numeric>,example alternative,
but will fail for inputs of the format:
example unknown_subcommand,example normal not_a_number.example alternative unnecessary_argument.
Credits
- MnPX, codebase design.