@wq2/brigadier-ts 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/CommandDispatcher.d.ts +7 -1
- package/dist/CommandDispatcher.js +26 -20
- package/dist/tree/ArgumentCommandNode.d.ts +2 -0
- package/dist/tree/ArgumentCommandNode.js +2 -0
- package/dist/tree/CommandNode.d.ts +8 -0
- package/dist/tree/CommandNode.js +10 -3
- package/dist/tree/LiteralCommandNode.d.ts +2 -0
- package/dist/tree/LiteralCommandNode.js +2 -0
- package/dist/tree/internal.d.ts +3 -0
- package/dist/tree/internal.js +7 -0
- package/dist/tree/internal2.d.ts +6 -0
- package/dist/tree/internal2.js +10 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/CommandDispatcher.ts +10 -12
- package/src/builder/ArgumentBuilder.ts +3 -1
- package/src/tree/ArgumentCommandNode.ts +2 -0
- package/src/tree/CommandNode.ts +16 -5
- package/src/tree/LiteralCommandNode.ts +2 -0
- package/src/tree/internal.ts +9 -0
- package/src/tree/internal2.ts +6 -0
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@ Fork of [brigadier-ts](https://github.com/misode/brigadier-ts) with some changes
|
|
|
4
4
|
|
|
5
5
|
- (breaking change) Predicates and Commands are async
|
|
6
6
|
- Non-literal arguments don't unconditionally return empty suggestions (WHY DID THIS EXIST???)
|
|
7
|
+
- No circular dependencies
|
|
7
8
|
- Update branding
|
|
8
9
|
|
|
9
10
|
(not many, but we'll probably add more later)
|
|
@@ -24,7 +25,7 @@ import {
|
|
|
24
25
|
IntegerArgumentType,
|
|
25
26
|
literal,
|
|
26
27
|
argument
|
|
27
|
-
} from "brigadier-ts";
|
|
28
|
+
} from "@wq2/brigadier-ts";
|
|
28
29
|
|
|
29
30
|
class CommandSource {
|
|
30
31
|
private a: number;
|
|
@@ -62,7 +63,7 @@ import {
|
|
|
62
63
|
IntegerArgumentType,
|
|
63
64
|
literal,
|
|
64
65
|
argument
|
|
65
|
-
} from "brigadier-ts";
|
|
66
|
+
} from "@wq2/brigadier-ts";
|
|
66
67
|
|
|
67
68
|
const dispatcher = new CommandDispatcher<number>();
|
|
68
69
|
const execute = dispatcher.register(literal("execute"));
|
|
@@ -100,7 +101,7 @@ import {
|
|
|
100
101
|
IntegerArgumentType,
|
|
101
102
|
literal,
|
|
102
103
|
argument
|
|
103
|
-
} from "brigadier-ts";
|
|
104
|
+
} from "@wq2/brigadier-ts";
|
|
104
105
|
|
|
105
106
|
const dispatcher = new CommandDispatcher<number>();
|
|
106
107
|
dispatcher.register(literal("double")
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { LiteralArgumentBuilder } from "./builder/LiteralArgumentBuilder";
|
|
2
|
+
import { ParseResults } from "./ParseResults";
|
|
3
|
+
import { StringReader } from "./StringReader";
|
|
4
|
+
import { Suggestions } from "./suggestion/Suggestions";
|
|
5
|
+
import type { CommandNode } from "./tree/CommandNode";
|
|
6
|
+
import type { LiteralCommandNode } from "./tree/LiteralCommandNode";
|
|
7
|
+
import { RootCommandNode } from "./tree/RootCommandNode";
|
|
2
8
|
export declare class CommandDispatcher<S> {
|
|
3
9
|
private root;
|
|
4
10
|
private static USAGE_OPTIONAL_OPEN;
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandDispatcher = void 0;
|
|
4
|
-
const
|
|
4
|
+
const CommandContextBuilder_1 = require("./context/CommandContextBuilder");
|
|
5
|
+
const CommandSyntaxError_1 = require("./exceptions/CommandSyntaxError");
|
|
6
|
+
const ParseResults_1 = require("./ParseResults");
|
|
7
|
+
const StringReader_1 = require("./StringReader");
|
|
8
|
+
const Suggestions_1 = require("./suggestion/Suggestions");
|
|
9
|
+
const SuggestionsBuilder_1 = require("./suggestion/SuggestionsBuilder");
|
|
10
|
+
const RootCommandNode_1 = require("./tree/RootCommandNode");
|
|
5
11
|
class CommandDispatcher {
|
|
6
12
|
constructor() {
|
|
7
|
-
this.root = new
|
|
13
|
+
this.root = new RootCommandNode_1.RootCommandNode();
|
|
8
14
|
}
|
|
9
15
|
register(command) {
|
|
10
16
|
const build = command.build();
|
|
@@ -13,17 +19,17 @@ class CommandDispatcher {
|
|
|
13
19
|
}
|
|
14
20
|
async execute(parse, source) {
|
|
15
21
|
if (typeof parse === "string") {
|
|
16
|
-
parse = await this.parse(new
|
|
22
|
+
parse = await this.parse(new StringReader_1.StringReader(parse), source);
|
|
17
23
|
}
|
|
18
24
|
if (parse.getReader().canRead()) {
|
|
19
25
|
if (parse.getErrors().size === 1) {
|
|
20
26
|
throw parse.getErrors().values().next();
|
|
21
27
|
}
|
|
22
28
|
else if (parse.getContext().getRange().isEmpty()) {
|
|
23
|
-
throw
|
|
29
|
+
throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
|
24
30
|
}
|
|
25
31
|
else {
|
|
26
|
-
throw
|
|
32
|
+
throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_UNKNOWN_ARGUMENT.createWithContext(parse.getReader());
|
|
27
33
|
}
|
|
28
34
|
}
|
|
29
35
|
let result = 0;
|
|
@@ -78,13 +84,13 @@ class CommandDispatcher {
|
|
|
78
84
|
next = [];
|
|
79
85
|
}
|
|
80
86
|
if (!foundCommand) {
|
|
81
|
-
throw
|
|
87
|
+
throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_UNKNOWN_COMMAND.createWithContext(parse.getReader());
|
|
82
88
|
}
|
|
83
89
|
return forked ? successfulForks : result;
|
|
84
90
|
}
|
|
85
91
|
async parse(reader, source) {
|
|
86
|
-
reader = new
|
|
87
|
-
const context = new
|
|
92
|
+
reader = new StringReader_1.StringReader(reader);
|
|
93
|
+
const context = new CommandContextBuilder_1.CommandContextBuilder(this, source, this.root, reader.getCursor());
|
|
88
94
|
return this.parseNodes(this.root, reader, context);
|
|
89
95
|
}
|
|
90
96
|
async parseNodes(node, originalReader, contextSoFar) {
|
|
@@ -97,25 +103,25 @@ class CommandDispatcher {
|
|
|
97
103
|
continue;
|
|
98
104
|
}
|
|
99
105
|
const context = contextSoFar.copy();
|
|
100
|
-
const reader = new
|
|
106
|
+
const reader = new StringReader_1.StringReader(originalReader);
|
|
101
107
|
try {
|
|
102
108
|
try {
|
|
103
109
|
child.parse(reader, context);
|
|
104
110
|
}
|
|
105
111
|
catch (e) {
|
|
106
|
-
if (e instanceof
|
|
112
|
+
if (e instanceof CommandSyntaxError_1.CommandSyntaxError) {
|
|
107
113
|
throw e;
|
|
108
114
|
}
|
|
109
115
|
else {
|
|
110
|
-
throw
|
|
116
|
+
throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_PARSE_ERROR.createWithContext(reader, e.message);
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
119
|
if (reader.canRead() && reader.peek() !== " ") {
|
|
114
|
-
throw
|
|
120
|
+
throw CommandSyntaxError_1.CommandSyntaxError.DISPATCHER_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(reader);
|
|
115
121
|
}
|
|
116
122
|
}
|
|
117
123
|
catch (e) {
|
|
118
|
-
if (e instanceof
|
|
124
|
+
if (e instanceof CommandSyntaxError_1.CommandSyntaxError) {
|
|
119
125
|
errors.set(child, e);
|
|
120
126
|
reader.setCursor(cursor);
|
|
121
127
|
continue;
|
|
@@ -128,21 +134,21 @@ class CommandDispatcher {
|
|
|
128
134
|
if (reader.canRead(child.getRedirect() === null ? 2 : 1)) {
|
|
129
135
|
reader.skip();
|
|
130
136
|
if (child.getRedirect()) {
|
|
131
|
-
const childContext = new
|
|
137
|
+
const childContext = new CommandContextBuilder_1.CommandContextBuilder(this, source, child.getRedirect(), reader.getCursor());
|
|
132
138
|
const parse = await this.parseNodes(child.getRedirect(), reader, childContext);
|
|
133
139
|
context.withChild(parse.getContext());
|
|
134
|
-
return new
|
|
140
|
+
return new ParseResults_1.ParseResults(context, parse.getReader(), parse.getErrors());
|
|
135
141
|
}
|
|
136
142
|
else {
|
|
137
143
|
potentials.push(this.parseNodes(child, reader, context));
|
|
138
144
|
}
|
|
139
145
|
}
|
|
140
146
|
else {
|
|
141
|
-
potentials.push(new
|
|
147
|
+
potentials.push(new ParseResults_1.ParseResults(context, reader, new Map()));
|
|
142
148
|
}
|
|
143
149
|
}
|
|
144
150
|
if (potentials.length === 0) {
|
|
145
|
-
potentials.push(new
|
|
151
|
+
potentials.push(new ParseResults_1.ParseResults(contextSoFar, originalReader, errors));
|
|
146
152
|
}
|
|
147
153
|
return potentials[0];
|
|
148
154
|
}
|
|
@@ -187,9 +193,9 @@ class CommandDispatcher {
|
|
|
187
193
|
const truncatedInput = fullInput.substring(0, cursor);
|
|
188
194
|
const promises = [];
|
|
189
195
|
for (const node of parent.getChildren()) {
|
|
190
|
-
let promise =
|
|
196
|
+
let promise = Suggestions_1.Suggestions.empty();
|
|
191
197
|
try {
|
|
192
|
-
promise = node.listSuggestions(context.build(truncatedInput), new
|
|
198
|
+
promise = node.listSuggestions(context.build(truncatedInput), new SuggestionsBuilder_1.SuggestionsBuilder(truncatedInput, start));
|
|
193
199
|
}
|
|
194
200
|
catch (ignored) {
|
|
195
201
|
console.log("???", ignored);
|
|
@@ -197,7 +203,7 @@ class CommandDispatcher {
|
|
|
197
203
|
promises.push(promise);
|
|
198
204
|
}
|
|
199
205
|
const suggestions = await Promise.all(promises);
|
|
200
|
-
return
|
|
206
|
+
return Suggestions_1.Suggestions.merge(fullInput, suggestions);
|
|
201
207
|
}
|
|
202
208
|
getSmartUsage(node, source, optional, deep) {
|
|
203
209
|
if (optional === undefined && deep === undefined) {
|
|
@@ -8,9 +8,11 @@ import type { StringReader } from "../StringReader";
|
|
|
8
8
|
import type { Suggestions } from "../suggestion/Suggestions";
|
|
9
9
|
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
10
10
|
import { CommandNode } from "./CommandNode";
|
|
11
|
+
import CommandNodeThing from "./internal2";
|
|
11
12
|
export declare class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
|
12
13
|
name: string;
|
|
13
14
|
type: ArgumentType<T>;
|
|
15
|
+
_thing: CommandNodeThing;
|
|
14
16
|
constructor(name: string, type: ArgumentType<T>, command: Command<S>, requirement: Predicate<S>, redirect: CommandNode<S>, modifier: RedirectModifier<S>, forks: boolean);
|
|
15
17
|
getType(): ArgumentType<T>;
|
|
16
18
|
parse(reader: StringReader, contextBuilder: CommandContextBuilder<S>): void;
|
|
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ArgumentCommandNode = void 0;
|
|
4
4
|
const ParsedArgument_1 = require("../context/ParsedArgument");
|
|
5
5
|
const CommandNode_1 = require("./CommandNode");
|
|
6
|
+
const internal2_1 = require("./internal2");
|
|
6
7
|
class ArgumentCommandNode extends CommandNode_1.CommandNode {
|
|
7
8
|
constructor(name, type, command, requirement, redirect, modifier, forks) {
|
|
8
9
|
super(command, requirement, redirect, modifier, forks);
|
|
10
|
+
this._thing = internal2_1.default.ARGUMENT;
|
|
9
11
|
this.name = name;
|
|
10
12
|
this.type = type;
|
|
11
13
|
}
|
|
@@ -6,6 +6,7 @@ import type { Predicate } from "../Predicate";
|
|
|
6
6
|
import type { StringReader } from "../StringReader";
|
|
7
7
|
import type { Suggestions } from "../suggestion/Suggestions";
|
|
8
8
|
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
9
|
+
import CommandNodeThing from "./internal2";
|
|
9
10
|
export declare abstract class CommandNode<S> {
|
|
10
11
|
private children;
|
|
11
12
|
private literals;
|
|
@@ -15,6 +16,13 @@ export declare abstract class CommandNode<S> {
|
|
|
15
16
|
private redirect;
|
|
16
17
|
private modifier;
|
|
17
18
|
private forks;
|
|
19
|
+
/**
|
|
20
|
+
* This is used for detecting what type of command node this is, without having circular dependencies.
|
|
21
|
+
* @internal
|
|
22
|
+
* @hidden
|
|
23
|
+
* @protected
|
|
24
|
+
*/
|
|
25
|
+
_thing: CommandNodeThing;
|
|
18
26
|
constructor(command: Command<S>, requirement: Predicate<S>, redirect: CommandNode<S>, modifier: RedirectModifier<S>, forks: boolean);
|
|
19
27
|
getCommand(): Command<S>;
|
|
20
28
|
getChildren(): CommandNode<S>[];
|
package/dist/tree/CommandNode.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandNode = void 0;
|
|
4
|
-
const
|
|
4
|
+
const internal2_1 = require("./internal2");
|
|
5
5
|
class CommandNode {
|
|
6
6
|
constructor(command, requirement, redirect, modifier, forks) {
|
|
7
|
+
/**
|
|
8
|
+
* This is used for detecting what type of command node this is, without having circular dependencies.
|
|
9
|
+
* @internal
|
|
10
|
+
* @hidden
|
|
11
|
+
* @protected
|
|
12
|
+
*/
|
|
13
|
+
this._thing = internal2_1.default.UNSPECIFIED;
|
|
7
14
|
this.children = new Map();
|
|
8
15
|
this.literals = new Map();
|
|
9
16
|
this.arguments = new Map();
|
|
@@ -46,10 +53,10 @@ class CommandNode {
|
|
|
46
53
|
}
|
|
47
54
|
else {
|
|
48
55
|
this.children.set(node.getName(), node);
|
|
49
|
-
if (node
|
|
56
|
+
if (node._thing === internal2_1.default.LITERAL) {
|
|
50
57
|
this.literals.set(node.getName(), node);
|
|
51
58
|
}
|
|
52
|
-
else if (node
|
|
59
|
+
else if (node._thing === internal2_1.default.ARGUMENT) {
|
|
53
60
|
this.arguments.set(node.getName(), node);
|
|
54
61
|
}
|
|
55
62
|
}
|
|
@@ -7,8 +7,10 @@ import type { StringReader } from "../StringReader";
|
|
|
7
7
|
import { Suggestions } from "../suggestion/Suggestions";
|
|
8
8
|
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
9
9
|
import { CommandNode } from "./CommandNode";
|
|
10
|
+
import CommandNodeThing from "./internal2";
|
|
10
11
|
export declare class LiteralCommandNode<S> extends CommandNode<S> {
|
|
11
12
|
private literal;
|
|
13
|
+
_thing: CommandNodeThing;
|
|
12
14
|
constructor(literal: string, command: Command<S>, requirement: Predicate<S>, redirect: CommandNode<S>, modifier: RedirectModifier<S>, forks: boolean);
|
|
13
15
|
parse(reader: StringReader, contextBuilder: CommandContextBuilder<S>): void;
|
|
14
16
|
private parseInternal;
|
|
@@ -5,9 +5,11 @@ const StringRange_1 = require("../context/StringRange");
|
|
|
5
5
|
const CommandSyntaxError_1 = require("../exceptions/CommandSyntaxError");
|
|
6
6
|
const Suggestions_1 = require("../suggestion/Suggestions");
|
|
7
7
|
const CommandNode_1 = require("./CommandNode");
|
|
8
|
+
const internal2_1 = require("./internal2");
|
|
8
9
|
class LiteralCommandNode extends CommandNode_1.CommandNode {
|
|
9
10
|
constructor(literal, command, requirement, redirect, modifier, forks) {
|
|
10
11
|
super(command, requirement, redirect, modifier, forks);
|
|
12
|
+
this._thing = internal2_1.default.LITERAL;
|
|
11
13
|
this.literal = literal;
|
|
12
14
|
}
|
|
13
15
|
parse(reader, contextBuilder) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandNodeThing = void 0;
|
|
4
|
+
var CommandNodeThing;
|
|
5
|
+
(function (CommandNodeThing) {
|
|
6
|
+
CommandNodeThing[CommandNodeThing["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
7
|
+
CommandNodeThing[CommandNodeThing["ARGUMENT"] = 1] = "ARGUMENT";
|
|
8
|
+
CommandNodeThing[CommandNodeThing["LITERAL"] = 2] = "LITERAL";
|
|
9
|
+
})(CommandNodeThing || (exports.CommandNodeThing = CommandNodeThing = {}));
|
|
10
|
+
exports.default = CommandNodeThing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/Command.ts","../src/CommandDispatcher.ts","../src/ParseResults.ts","../src/Predicate.ts","../src/StringReader.ts","../src/index.ts","../src/arguments/ArgumentType.ts","../src/arguments/BoolArgumentType.ts","../src/arguments/FloatArgumentType.ts","../src/arguments/IntegerArgumentType.ts","../src/arguments/LongArgumentType.ts","../src/arguments/NumberArgumentType.ts","../src/arguments/StringArgumentType.ts","../src/builder/ArgumentBuilder.ts","../src/builder/LiteralArgumentBuilder.ts","../src/builder/RequiredArgumentBuilder.ts","../src/context/CommandContext.ts","../src/context/CommandContextBuilder.ts","../src/context/ParsedArgument.ts","../src/context/ParsedCommandNode.ts","../src/context/StringRange.ts","../src/context/SuggestionContext.ts","../src/exceptions/CommandErrorType.ts","../src/exceptions/CommandSyntaxError.ts","../src/suggestion/Suggestion.ts","../src/suggestion/Suggestions.ts","../src/suggestion/SuggestionsBuilder.ts","../src/tree/ArgumentCommandNode.ts","../src/tree/CommandNode.ts","../src/tree/LiteralCommandNode.ts","../src/tree/RootCommandNode.ts"],"version":"5.9.3"}
|
|
1
|
+
{"root":["../src/Command.ts","../src/CommandDispatcher.ts","../src/ParseResults.ts","../src/Predicate.ts","../src/StringReader.ts","../src/index.ts","../src/arguments/ArgumentType.ts","../src/arguments/BoolArgumentType.ts","../src/arguments/FloatArgumentType.ts","../src/arguments/IntegerArgumentType.ts","../src/arguments/LongArgumentType.ts","../src/arguments/NumberArgumentType.ts","../src/arguments/StringArgumentType.ts","../src/builder/ArgumentBuilder.ts","../src/builder/LiteralArgumentBuilder.ts","../src/builder/RequiredArgumentBuilder.ts","../src/context/CommandContext.ts","../src/context/CommandContextBuilder.ts","../src/context/ParsedArgument.ts","../src/context/ParsedCommandNode.ts","../src/context/StringRange.ts","../src/context/SuggestionContext.ts","../src/exceptions/CommandErrorType.ts","../src/exceptions/CommandSyntaxError.ts","../src/suggestion/Suggestion.ts","../src/suggestion/Suggestions.ts","../src/suggestion/SuggestionsBuilder.ts","../src/tree/ArgumentCommandNode.ts","../src/tree/CommandNode.ts","../src/tree/LiteralCommandNode.ts","../src/tree/RootCommandNode.ts","../src/tree/internal.ts","../src/tree/internal2.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
package/src/CommandDispatcher.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
SuggestionsBuilder,
|
|
12
|
-
} from ".";
|
|
1
|
+
import type { LiteralArgumentBuilder } from "./builder/LiteralArgumentBuilder";
|
|
2
|
+
import { CommandContextBuilder } from "./context/CommandContextBuilder";
|
|
3
|
+
import { CommandSyntaxError } from "./exceptions/CommandSyntaxError";
|
|
4
|
+
import { ParseResults } from "./ParseResults";
|
|
5
|
+
import { StringReader } from "./StringReader";
|
|
6
|
+
import { Suggestions } from "./suggestion/Suggestions";
|
|
7
|
+
import { SuggestionsBuilder } from "./suggestion/SuggestionsBuilder";
|
|
8
|
+
import type { CommandNode } from "./tree/CommandNode";
|
|
9
|
+
import type { LiteralCommandNode } from "./tree/LiteralCommandNode";
|
|
10
|
+
import { RootCommandNode } from "./tree/RootCommandNode";
|
|
13
11
|
|
|
14
12
|
export class CommandDispatcher<S> {
|
|
15
13
|
private root: RootCommandNode<S>;
|
|
@@ -22,7 +22,9 @@ export abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
|
|
|
22
22
|
abstract getThis(): T;
|
|
23
23
|
|
|
24
24
|
// biome-ignore lint/suspicious/noThenProperty: proof?
|
|
25
|
-
then<A extends ArgumentBuilder<S, A>>(
|
|
25
|
+
then<A extends ArgumentBuilder<S, A>>(
|
|
26
|
+
argument: ArgumentBuilder<S, A> | CommandNode<S>,
|
|
27
|
+
): T {
|
|
26
28
|
const child = argument instanceof CommandNode ? argument : argument.build();
|
|
27
29
|
this.arguments.addChild(child);
|
|
28
30
|
return this.getThis();
|
|
@@ -9,10 +9,12 @@ import type { StringReader } from "../StringReader";
|
|
|
9
9
|
import type { Suggestions } from "../suggestion/Suggestions";
|
|
10
10
|
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
11
11
|
import { CommandNode } from "./CommandNode";
|
|
12
|
+
import CommandNodeThing from "./internal2";
|
|
12
13
|
|
|
13
14
|
export class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
|
14
15
|
name: string;
|
|
15
16
|
type: ArgumentType<T>;
|
|
17
|
+
_thing: CommandNodeThing = CommandNodeThing.ARGUMENT;
|
|
16
18
|
|
|
17
19
|
constructor(
|
|
18
20
|
name: string,
|
package/src/tree/CommandNode.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArgumentCommandNode, LiteralCommandNode } from "..";
|
|
1
|
+
import type { ArgumentCommandNode, LiteralCommandNode } from "..";
|
|
2
2
|
import type { RedirectModifier } from "../builder/ArgumentBuilder";
|
|
3
3
|
import type { Command } from "../Command";
|
|
4
4
|
import type { CommandContext } from "../context/CommandContext";
|
|
@@ -7,6 +7,7 @@ import type { Predicate } from "../Predicate";
|
|
|
7
7
|
import type { StringReader } from "../StringReader";
|
|
8
8
|
import type { Suggestions } from "../suggestion/Suggestions";
|
|
9
9
|
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
10
|
+
import CommandNodeThing from "./internal2";
|
|
10
11
|
|
|
11
12
|
export abstract class CommandNode<S> {
|
|
12
13
|
private children: Map<string, CommandNode<S>>;
|
|
@@ -17,6 +18,13 @@ export abstract class CommandNode<S> {
|
|
|
17
18
|
private redirect: CommandNode<S>;
|
|
18
19
|
private modifier: RedirectModifier<S>;
|
|
19
20
|
private forks: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* This is used for detecting what type of command node this is, without having circular dependencies.
|
|
23
|
+
* @internal
|
|
24
|
+
* @hidden
|
|
25
|
+
* @protected
|
|
26
|
+
*/
|
|
27
|
+
_thing: CommandNodeThing = CommandNodeThing.UNSPECIFIED;
|
|
20
28
|
|
|
21
29
|
constructor(
|
|
22
30
|
command: Command<S>,
|
|
@@ -74,10 +82,13 @@ export abstract class CommandNode<S> {
|
|
|
74
82
|
});
|
|
75
83
|
} else {
|
|
76
84
|
this.children.set(node.getName(), node);
|
|
77
|
-
if (node
|
|
78
|
-
this.literals.set(node.getName(), node);
|
|
79
|
-
} else if (node
|
|
80
|
-
this.arguments.set(
|
|
85
|
+
if (node._thing === CommandNodeThing.LITERAL) {
|
|
86
|
+
this.literals.set(node.getName(), node as LiteralCommandNode<S>);
|
|
87
|
+
} else if (node._thing === CommandNodeThing.ARGUMENT) {
|
|
88
|
+
this.arguments.set(
|
|
89
|
+
node.getName(),
|
|
90
|
+
node as ArgumentCommandNode<S, unknown>,
|
|
91
|
+
);
|
|
81
92
|
}
|
|
82
93
|
}
|
|
83
94
|
}
|
|
@@ -9,9 +9,11 @@ import type { StringReader } from "../StringReader";
|
|
|
9
9
|
import { Suggestions } from "../suggestion/Suggestions";
|
|
10
10
|
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
11
11
|
import { CommandNode } from "./CommandNode";
|
|
12
|
+
import CommandNodeThing from "./internal2";
|
|
12
13
|
|
|
13
14
|
export class LiteralCommandNode<S> extends CommandNode<S> {
|
|
14
15
|
private literal: string;
|
|
16
|
+
_thing: CommandNodeThing = CommandNodeThing.LITERAL;
|
|
15
17
|
|
|
16
18
|
constructor(
|
|
17
19
|
literal: string,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ArgumentCommandNode } from "./ArgumentCommandNode";
|
|
2
|
+
import type { CommandNode } from "./CommandNode";
|
|
3
|
+
import CommandNodeThing from "./internal2";
|
|
4
|
+
|
|
5
|
+
export function isArgumentNode<A>(
|
|
6
|
+
n: CommandNode<A>,
|
|
7
|
+
): n is ArgumentCommandNode<A, unknown> {
|
|
8
|
+
return n._thing === CommandNodeThing.ARGUMENT;
|
|
9
|
+
}
|