- Export
toSafeSignature()
to convert fromTSignature
toTSafeSignautre
- BREAKING CHANGE: Command signature objects (
TSignature
) may now includeundefined
properties for type purposes- See the comment for
TSignature
for an in-depth explanation of this - These properties are silently ignored if actually included in the signature objects
- See the comment for
- Add proper method signature overloads for ``
- Invalid option values no longer dump the entire type conversion function in the error
- Reworded errors for invalid argument/option values
- Improved type hints for default type helpers (
string()
,number()
,bool()
,switchOption()
) and custom type helpers created withcreateTypeHelper()
- New helper function:
createTypeHelper()
- This function can be used to create a helper wrapper for a parameter/option type
- Type tests added for default parameter/option types
Version 8.0.0
comes with several changes aimed at simplifying the API and
providing a better base for type inference in applications using knub-command-manager
.
-
You can no longer pass parameters as a string and have it implicitly parsed. Instead, use the
parseSignature
function.From:
manager.add("foo", "<arg1> <arg2>")
To:
import { parseSignature as p } from "knub-command-manager" manager.add("foo", p("<arg1> <arg2>"))
-
Parameters are now specified as an object rather than an array.
From:
manager.add("foo", [ { name: "arg1", type: "string" }, { name: "arg2", type: "number" } ])
To:
manager.add("foo", { arg1: { type: t.string }, arg2: { type: t.number } })
-
Types are now specified as the type conversion function directly. This also means that the CommandManager object no longer has an internal "types" object for converting from string types to the actual function.
From:
manager.add("foo", { arg1: { type: "string" }, arg2: { type: "number" } })
To:
import { defaultTypeConverters as t } from "knub-command-manager"; manager.add("foo", { arg1: { type: t.string }, arg2: { type: t.number } })
-
There are several helper functions for the default types.
From:
import { defaultTypeConverters as t } from "knub-command-manager"; manager.add("foo", { arg1: { type: t.string }, arg2: { type: t.number } })
To:
import { string, number } from "knub-command-manager"; manager.add("foo", { arg1: string(), arg2: number() })
-
parseSignature
now takes extra parameters for parameter types:// parseSignature(signature, types, defaultType) parseSignature("<foo:mytype>", { mytype: () => { /* ... */ } }, "mytype")
-
-
Options are no longer specified in the command's config. Instead, options are now specified as part of the command's signature:
From:
manager.add("foo", [], { options: [ { name: "myopt", shortcut: "o", type: "string" }, ], })
To:
manager.add("foo", { myopt: string({ option: true, shortcut: "o" }) })
Or with
parseSignature
:manager.add("foo", parseSignature("-myopt|o"))
-
Aliases are no longer specified in the command's config. Instead, you can now set an array as the command's trigger.
From:
manager.add("foo", [], { aliases: ["bar"] })
To:
manager.add(["foo", "bar"])
-
Overloads are no longer specified in the command's config. Instead, you can now set an array as the command's signature.
From:
manager.add("foo", "<foo> <bar>", { overloads: ["<baz>"] })
To:
manager.add("foo", [ p("<foo> <bar>"), p("<baz>") ])
-
Deprecated
CommandManager.findMatchingCommandResultHasError()
. UseisError()
instead. -
IMatchedCommand
now contains avalues
property that replaces the previousargs
andopts
properties.- This interface is returned by
CommandManager.findMatchingCommand()
andCommandManager.tryMatchingCommand()
- This interface is returned by
- The previously-internal
CommandManager.tryMatchingCommand()
is now a public method. It can be used to do more granular matching than withCommandManager.findMatchingCommand()
.
- You can now escape characters for argument parsing with a backslash (
\
)- This bumps the major version since it is technically a breaking change to argument parsing (since backslashes are now effectively ignored unless also escaped)
- Fix bug where options with quotes would be interpreted as arguments and e.g. get included in catch-all arguments
- The original prefix of a command (i.e. like it was before it was converted to
the internal regex version) is now available in
CommandDefinition.originalPrefix
- Add
CommandManager.getDefaultPrefix()
to get the internal regex version of the current default prefix for added commands. This is based on theprefix
option passed inCommandManager
options, ornull
if none was passed - Add
CommandManager.getOriginalDefaultPrefix()
to get the original value of theprefix
option passed inCommandManager
options
- Options and their shortcuts can now be used with the same prefix, e.g.
-option
and-o
both work by default, as do--option
and--o
. Previously--
was reserved for full option names and-
was reserved for shortcuts. This change was made to make option usage more intuitive. - You can now specify which option prefixes you want to use with the
optionPrefixes
CommandManager config option. The default prefixes are--
and-
. - BREAKING CHANGE: Undocumented but previously-supported option combining
(e.g.
-abcd
where a, b, c, and d are all different options) is no longer supported due to the changes above - BREAKING CHANGE: Undocumented but previously-supported syntax
!cmd arg1 arg2 -- this is all arg3
where--
forces the rest of the arguments to be treated as if they were all one quoted argument is now deprecated. It wasn't a very well known syntax and quotes do the job well enough.
- Add support for async type conversion functions
- In other words, the command manager will wait for any promises returned by type conversion functions to resolve with the converted value
- Add and export
isFlagOption
type guard
- Add support for command signature overloads via new
overloads
property in command config - Rename all exported types/interfaces to have an I/T prefix (depending on
whether it's a type or an interface)
- E.g.
CommandConfig
->ICommandConfig
- E.g.
- Include trigger sources (i.e. as they were supplied to
CommandManager.add()
) inCommandDefinition.originalTriggers
- This is an array that also includes the sources of any specified aliases
- Add
CommandManager.getAll()
to get all registered commands
- When
CommandManager.findMatchingCommands()
returns an error (the{ error: string }
return object), the definition of the last command that triggered an error will now also be returned (as thecommand
property)
- All types from
src/types.ts
are now exported from the main script
- BREAKING CHANGE: Instead of being able to specify the type of command
config directly (as the second generic type of
CommandManager
), you can now specify the type of anextra
property in the config - Filter context (
TFilterContext
, now calledTContext
) is now also passed to type conversion functions as the second parameter, allowing context-aware argument/option types
- Dev dependency updates. New release so the
package.json
on npm and GitHub are the same.
- Include
typings
in package.json
- Move
CommandManager.parseParameterString()
to a standalone function calledparseParameters
and export it
- The original command config object is now accessible through the
config
property on the command definition object (returned byadd()
) CommandManager
now has a second type you can specify: the type of the command config object. This type must extend the originalCommandConfig
type
- Fix incorrect parsing of catch-all arguments as first arguments
- The catch-all argument also included the preceding space
- Triggers now only match if they're followed by whitespace or the end of the
string. This fixes short triggers, e.g.
s
, matching the beginning of longer triggers, e.g.suspend
.
- Fix prefixes and triggers matching anywhere in the string
- Export
TypeConversionError
- Deprecate
TCustomProps
generic type that was used to store data with commands - Add
TFilterContext
generic type to CommandManager. Setting this allows you to pass additional context data when callingfindMatchingCommand(str, context)
which can be accessed in filter functions as the second argument. Useful for e.g. passing the message object where the command was called from in Discord bots.
- Split filters into pre-filters and post-filters. The old filters were equivalent to post filters
- Options within "quoted" arguments are now ignored
- As before, anything after
--
is counted as the last argument, but now it's also considered to be "quoted" for the purposes of matching options
- Initial release