Compare commits

...

2 Commits

Author SHA1 Message Date
6d921d6dec v1.6.8 2024-03-28 21:07:44 +02:00
54423a9395 Remove outdated code 2024-03-28 21:07:11 +02:00
5 changed files with 19 additions and 20 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@navy.gif/commandparser",
"version": "1.6.7",
"version": "1.6.8",
"description": "Parser meant to parse commands and their options for discord bots",
"author": "Navy.gif",
"license": "MIT",

View File

@ -73,7 +73,6 @@ class Parser extends EventEmitter
#globalFlags: CommandOption[];
#allowIncompleteReturn: string[];
constructor ({ commands, prefix, debug = false, resolver,
allowDefaultOnRequired, globalFlags = [], allowIncompleteReturn }: ParserOptions)
{

View File

@ -23,16 +23,7 @@ abstract class Command implements ICommand
this.aliases = def.aliases || [];
this.help = def.help;
// Add a built-in help flag to any non-subcommand option
this.options = [
new CommandOption({
name: 'help',
type: OptionType.BOOLEAN,
flag: true,
valueOptional: true,
defaultValue: true
})
];
this.options = [ ];
for (const opt of def.options || [])
{

View File

@ -39,14 +39,6 @@ class CommandOption implements ICommandOption
this.help = def.help;
this.options = [];
if (SUB.includes(this.type))
this.options.push(new CommandOption({
name: 'help',
type: OptionType.BOOLEAN,
flag: true,
valueOptional: true,
defaultValue: true
}));
for (const opt of def.options || [])
{

View File

@ -1,6 +1,20 @@
import { Parser, Command, OptionType } from '../build/esm/index.js';
const commands = [
new Command({
name: 'test',
options: [{
name: 'sub',
type: OptionType.SUB_COMMAND,
options: [{
name: 'flag',
type: OptionType.BOOLEAN,
defaultValue: true,
valueOptional: true,
flag: true
}]
}]
}),
new Command({
name: 'create',
options: [{
@ -52,6 +66,7 @@ const commands = [
})
];
const [first] = commands;
const parser = new Parser({
commands, prefix: '', debug: true,
globalFlags: [{
@ -67,6 +82,8 @@ parser.on('debug', console.log);
console.log((await parser.parseMessage('create code -a 1')));
console.log((await parser.parseMessage('create code --help')));
console.log(await parser.parseMessage('create --help'));
console.log((await parser.parseMessage('test sub --help')));
console.log(first.subcommand('sub').options);
console.log((await parser.parseMessage('create code')));