A library for creating text-chat commands that can receive strongly-typed argument data
Find a file
2026-04-22 23:22:09 +10:00
src feat: functions exist to generate usage information for commands 2026-04-22 20:06:37 +10:00
.gitignore Initial commit 2026-04-21 13:25:11 +10:00
eslint.config.ts chore(format): ESLint rules established to remove redundant whitespaces 2026-04-21 17:00:54 +10:00
LICENCE.md feat: project is licenced under GPLv3 2026-04-21 17:00:54 +10:00
package.json feat: tsup package used to create dist 2026-04-22 23:19:39 +10:00
pnpm-lock.yaml feat: tsup package used to create dist 2026-04-22 23:19:39 +10:00
README.md fix(README): markdown formatting for example failures clarified 2026-04-22 23:22:09 +10:00
tsconfig.json feat: basic project structure and some argument parsing is supported 2026-04-21 13:25:11 +10:00
tsup.config.ts feat: tsup package used to create dist 2026-04-22 23:19:39 +10:00

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.

  • literal will match a single token that exactly matches a given input,
  • word will match any one token,
  • numeric will match any stringified, base-10 number and can be specified to only match integers,
  • repeated will match the same argument repeated zero or numerous times,
  • remainder will 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.