Compare commits
2 Commits
b41c076181
...
6d921d6dec
Author | SHA1 | Date | |
---|---|---|---|
6d921d6dec | |||
54423a9395 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@navy.gif/commandparser",
|
"name": "@navy.gif/commandparser",
|
||||||
"version": "1.6.7",
|
"version": "1.6.8",
|
||||||
"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",
|
||||||
|
@ -73,7 +73,6 @@ class Parser extends EventEmitter
|
|||||||
#globalFlags: CommandOption[];
|
#globalFlags: CommandOption[];
|
||||||
#allowIncompleteReturn: string[];
|
#allowIncompleteReturn: string[];
|
||||||
|
|
||||||
|
|
||||||
constructor ({ commands, prefix, debug = false, resolver,
|
constructor ({ commands, prefix, debug = false, resolver,
|
||||||
allowDefaultOnRequired, globalFlags = [], allowIncompleteReturn }: ParserOptions)
|
allowDefaultOnRequired, globalFlags = [], allowIncompleteReturn }: ParserOptions)
|
||||||
{
|
{
|
||||||
|
@ -23,16 +23,7 @@ abstract class Command implements ICommand
|
|||||||
this.aliases = def.aliases || [];
|
this.aliases = def.aliases || [];
|
||||||
this.help = def.help;
|
this.help = def.help;
|
||||||
|
|
||||||
// Add a built-in help flag to any non-subcommand option
|
this.options = [ ];
|
||||||
this.options = [
|
|
||||||
new CommandOption({
|
|
||||||
name: 'help',
|
|
||||||
type: OptionType.BOOLEAN,
|
|
||||||
flag: true,
|
|
||||||
valueOptional: true,
|
|
||||||
defaultValue: true
|
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const opt of def.options || [])
|
for (const opt of def.options || [])
|
||||||
{
|
{
|
||||||
|
@ -39,14 +39,6 @@ class CommandOption implements ICommandOption
|
|||||||
this.help = def.help;
|
this.help = def.help;
|
||||||
|
|
||||||
this.options = [];
|
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 || [])
|
for (const opt of def.options || [])
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,20 @@
|
|||||||
import { Parser, Command, OptionType } from '../build/esm/index.js';
|
import { Parser, Command, OptionType } from '../build/esm/index.js';
|
||||||
|
|
||||||
const commands = [
|
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({
|
new Command({
|
||||||
name: 'create',
|
name: 'create',
|
||||||
options: [{
|
options: [{
|
||||||
@ -52,6 +66,7 @@ const commands = [
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const [first] = commands;
|
||||||
const parser = new Parser({
|
const parser = new Parser({
|
||||||
commands, prefix: '', debug: true,
|
commands, prefix: '', debug: true,
|
||||||
globalFlags: [{
|
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 -a 1')));
|
||||||
console.log((await parser.parseMessage('create code --help')));
|
console.log((await parser.parseMessage('create code --help')));
|
||||||
console.log(await parser.parseMessage('create --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')));
|
console.log((await parser.parseMessage('create code')));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user