Compare commits
No commits in common. "94d1291ffbc9bee35da70c23582cd18fdcf4455e" and "fb46e09d704abefc2c8ecda732e6298174e24895" have entirely different histories.
94d1291ffb
...
fb46e09d70
2
index.ts
2
index.ts
@ -7,4 +7,4 @@ export { SubcommandOption } from './src/classes/SubcommandOption.js';
|
|||||||
|
|
||||||
export { IResolver } from './src/interfaces/Resolver.js';
|
export { IResolver } from './src/interfaces/Resolver.js';
|
||||||
export { OptionType, CommandOptionDefinition } from './src/interfaces/CommandOption.js';
|
export { OptionType, CommandOptionDefinition } from './src/interfaces/CommandOption.js';
|
||||||
export { CommandDefinition, ICommand } from './src/interfaces/Command.js';
|
export { CommandDefinition } from './src/interfaces/Command.js';
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@navy.gif/commandparser",
|
"name": "@navy.gif/commandparser",
|
||||||
"version": "1.5.3",
|
"version": "1.5.1",
|
||||||
"description": "Parser meant to parse commands and their options for discord bots",
|
"description": "Parser meant to parse commands and their options for discord bots",
|
||||||
"author": "Navy.gif",
|
"author": "Navy.gif",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
// eslint-disable-next-line max-classes-per-file
|
// eslint-disable-next-line max-classes-per-file
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
import Command from './classes/Command.js';
|
||||||
import CommandOption from './classes/CommandOption.js';
|
import CommandOption from './classes/CommandOption.js';
|
||||||
|
|
||||||
import { OptionType } from "./interfaces/CommandOption.js";
|
import { OptionType } from "./interfaces/CommandOption.js";
|
||||||
import IResolver from './interfaces/Resolver.js';
|
import IResolver from './interfaces/Resolver.js';
|
||||||
import ExtendedMap from "./util/Map.js";
|
import ExtendedMap from "./util/Map.js";
|
||||||
import Util from "./util/Util.js";
|
import Util from "./util/Util.js";
|
||||||
import { ICommand } from '../index.js';
|
|
||||||
|
|
||||||
type ArgsResult = {
|
type ArgsResult = {
|
||||||
[key: string]: CommandOption
|
[key: string]: CommandOption
|
||||||
@ -14,22 +14,22 @@ type ArgsResult = {
|
|||||||
|
|
||||||
type ParseResult = {
|
type ParseResult = {
|
||||||
args: ArgsResult,
|
args: ArgsResult,
|
||||||
command: ICommand,
|
command: Command,
|
||||||
subcommand: string | null,
|
subcommand: string | null,
|
||||||
subcommandGroup: string | null
|
subcommandGroup: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParserOptions = {
|
type ParserOptions = {
|
||||||
commands: Iterable<ICommand>,
|
commands: Iterable<Command>,
|
||||||
prefix?: string,
|
prefix?: string,
|
||||||
debug?: boolean,
|
debug?: boolean,
|
||||||
resolver?: IResolver,
|
resolver?: IResolver<unknown, unknown, unknown, unknown, unknown>,
|
||||||
allowDefaultOnRequired?: boolean
|
allowDefaultOnRequired?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParseOptions = {
|
type ParseOptions = {
|
||||||
prefix?: string,
|
prefix?: string,
|
||||||
commandFilter?: (cmd: ICommand) => boolean,
|
commandFilter?: (cmd: Command) => boolean,
|
||||||
guild?: unknown
|
guild?: unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,10 +39,10 @@ const flagReg = /(?:^| )(?<flag>(?:--[a-z0-9]{3,})|(?:-[a-z]{1,2}))(?:$| )/iu;
|
|||||||
|
|
||||||
class Parser extends EventEmitter {
|
class Parser extends EventEmitter {
|
||||||
|
|
||||||
private commands: ExtendedMap<string, ICommand>;
|
private commands: ExtendedMap<string, Command>;
|
||||||
private _debug = false;
|
private _debug = false;
|
||||||
prefix: string;
|
prefix: string;
|
||||||
resolver?: IResolver;
|
resolver?: IResolver<unknown, unknown, unknown, unknown, unknown>;
|
||||||
allowDefaultOnRequired: boolean;
|
allowDefaultOnRequired: boolean;
|
||||||
|
|
||||||
constructor ({ commands, prefix, debug = false, resolver, allowDefaultOnRequired }: ParserOptions) {
|
constructor ({ commands, prefix, debug = false, resolver, allowDefaultOnRequired }: ParserOptions) {
|
||||||
@ -50,7 +50,7 @@ class Parser extends EventEmitter {
|
|||||||
super();
|
super();
|
||||||
|
|
||||||
this._debug = debug;
|
this._debug = debug;
|
||||||
this.commands = new ExtendedMap<string, ICommand>();
|
this.commands = new ExtendedMap<string, Command>();
|
||||||
for (const command of commands)
|
for (const command of commands)
|
||||||
this.commands.set(command.name, command);
|
this.commands.set(command.name, command);
|
||||||
this.resolver = resolver;
|
this.resolver = resolver;
|
||||||
@ -60,7 +60,7 @@ class Parser extends EventEmitter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private matchCommand (name: string): ICommand | null {
|
private matchCommand (name: string): Command | null {
|
||||||
let command = null;
|
let command = null;
|
||||||
if (this.commands.has(name))
|
if (this.commands.has(name))
|
||||||
command = this.commands.get(name);
|
command = this.commands.get(name);
|
||||||
@ -138,7 +138,7 @@ class Parser extends EventEmitter {
|
|||||||
parseResult.subcommandGroup = group?.name || null;
|
parseResult.subcommandGroup = group?.name || null;
|
||||||
|
|
||||||
if (!subcommand)
|
if (!subcommand)
|
||||||
throw new ParseError(`Expecting subcommand, one of ${subcommands.map((s) => s.name).join(', ')}`); // return { showUsage: true, verbose: true };
|
throw new ParseError(`Expecting subcommand, one of ${subcommands.map((s) => s.name)}`); // return { showUsage: true, verbose: true };
|
||||||
this.debug(`Got ${subcommand.name}`);
|
this.debug(`Got ${subcommand.name}`);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user