@wq2/brigadier-ts 1.0.2 → 1.0.4
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/Command.d.ts +1 -1
- package/dist/CommandDispatcher.d.ts +1 -1
- package/dist/ParseResults.d.ts +1 -1
- package/dist/arguments/ArgumentType.d.ts +5 -2
- package/dist/arguments/ArgumentType.js +2 -2
- package/dist/arguments/BoolArgumentType.d.ts +4 -4
- package/dist/arguments/BoolArgumentType.js +3 -5
- package/dist/arguments/FloatArgumentType.d.ts +2 -1
- package/dist/arguments/FloatArgumentType.js +5 -4
- package/dist/arguments/IntegerArgumentType.d.ts +2 -1
- package/dist/arguments/IntegerArgumentType.js +5 -4
- package/dist/arguments/LongArgumentType.d.ts +2 -1
- package/dist/arguments/LongArgumentType.js +5 -4
- package/dist/arguments/NumberArgumentType.d.ts +3 -1
- package/dist/arguments/NumberArgumentType.js +2 -2
- package/dist/arguments/StringArgumentType.d.ts +2 -1
- package/dist/arguments/StringArgumentType.js +2 -2
- package/dist/builder/ArgumentBuilder.d.ts +5 -2
- package/dist/builder/ArgumentBuilder.js +4 -3
- package/dist/builder/LiteralArgumentBuilder.d.ts +3 -2
- package/dist/builder/LiteralArgumentBuilder.js +4 -3
- package/dist/builder/RequiredArgumentBuilder.d.ts +4 -2
- package/dist/builder/RequiredArgumentBuilder.js +4 -3
- package/dist/context/CommandContext.d.ts +8 -3
- package/dist/context/CommandContextBuilder.d.ts +10 -3
- package/dist/context/CommandContextBuilder.js +12 -9
- package/dist/context/ParsedArgument.d.ts +1 -1
- package/dist/context/ParsedArgument.js +2 -2
- package/dist/context/ParsedCommandNode.d.ts +2 -1
- package/dist/context/SuggestionContext.d.ts +1 -1
- package/dist/exceptions/CommandErrorType.d.ts +3 -2
- package/dist/exceptions/CommandErrorType.js +3 -3
- package/dist/exceptions/CommandSyntaxError.d.ts +1 -1
- package/dist/exceptions/CommandSyntaxError.js +23 -23
- package/dist/index.d.ts +18 -18
- package/dist/index.js +18 -18
- package/dist/suggestion/Suggestion.d.ts +1 -1
- package/dist/suggestion/Suggestions.d.ts +2 -1
- package/dist/suggestion/Suggestions.js +3 -3
- package/dist/suggestion/SuggestionsBuilder.d.ts +1 -1
- package/dist/suggestion/SuggestionsBuilder.js +5 -3
- package/dist/tree/ArgumentCommandNode.d.ts +12 -1
- package/dist/tree/ArgumentCommandNode.js +6 -3
- package/dist/tree/CommandNode.d.ts +16 -1
- package/dist/tree/CommandNode.js +10 -3
- package/dist/tree/LiteralCommandNode.d.ts +11 -1
- package/dist/tree/LiteralCommandNode.js +10 -5
- package/dist/tree/RootCommandNode.d.ts +6 -1
- package/dist/tree/RootCommandNode.js +4 -3
- 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/Command.ts +1 -1
- package/src/CommandDispatcher.ts +5 -5
- package/src/ParseResults.ts +1 -1
- package/src/arguments/ArgumentType.ts +5 -7
- package/src/arguments/BoolArgumentType.ts +6 -7
- package/src/arguments/FloatArgumentType.ts +3 -1
- package/src/arguments/IntegerArgumentType.ts +3 -1
- package/src/arguments/LongArgumentType.ts +3 -1
- package/src/arguments/NumberArgumentType.ts +3 -1
- package/src/arguments/StringArgumentType.ts +2 -1
- package/src/builder/ArgumentBuilder.ts +8 -8
- package/src/builder/LiteralArgumentBuilder.ts +3 -2
- package/src/builder/RequiredArgumentBuilder.ts +4 -2
- package/src/context/CommandContext.ts +10 -12
- package/src/context/CommandContextBuilder.ts +12 -14
- package/src/context/ParsedArgument.ts +1 -1
- package/src/context/ParsedCommandNode.ts +2 -1
- package/src/context/SuggestionContext.ts +1 -1
- package/src/exceptions/CommandErrorType.ts +3 -2
- package/src/exceptions/CommandSyntaxError.ts +1 -1
- package/src/index.ts +18 -18
- package/src/suggestion/Suggestion.ts +1 -1
- package/src/suggestion/Suggestions.ts +2 -1
- package/src/suggestion/SuggestionsBuilder.ts +3 -1
- package/src/tree/ArgumentCommandNode.ts +13 -13
- package/src/tree/CommandNode.ts +25 -17
- package/src/tree/LiteralCommandNode.ts +13 -13
- package/src/tree/RootCommandNode.ts +6 -8
- package/src/tree/internal.ts +9 -0
- package/src/tree/internal2.ts +6 -0
- package/test/Arguments.test.ts +3 -4
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type CommandContext,
|
|
7
|
-
} from "..";
|
|
1
|
+
import type { Command } from "../Command";
|
|
2
|
+
import type { CommandContext } from "../context/CommandContext";
|
|
3
|
+
import type { Predicate } from "../Predicate";
|
|
4
|
+
import { CommandNode } from "../tree/CommandNode";
|
|
5
|
+
import { RootCommandNode } from "../tree/RootCommandNode";
|
|
8
6
|
|
|
9
7
|
export type RedirectModifier<S> = (context: CommandContext<S>) => S | S[];
|
|
10
8
|
|
|
@@ -24,7 +22,9 @@ export abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
|
|
|
24
22
|
abstract getThis(): T;
|
|
25
23
|
|
|
26
24
|
// biome-ignore lint/suspicious/noThenProperty: proof?
|
|
27
|
-
then
|
|
25
|
+
then<A extends ArgumentBuilder<S, A>>(
|
|
26
|
+
argument: ArgumentBuilder<S, A> | CommandNode<S>,
|
|
27
|
+
): T {
|
|
28
28
|
const child = argument instanceof CommandNode ? argument : argument.build();
|
|
29
29
|
this.arguments.addChild(child);
|
|
30
30
|
return this.getThis();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LiteralCommandNode } from "../tree/LiteralCommandNode";
|
|
2
|
+
import { ArgumentBuilder } from "./ArgumentBuilder";
|
|
2
3
|
|
|
3
4
|
export class LiteralArgumentBuilder<S> extends ArgumentBuilder<
|
|
4
5
|
S,
|
|
@@ -35,6 +36,6 @@ export class LiteralArgumentBuilder<S> extends ArgumentBuilder<
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export function literal<S =
|
|
39
|
+
export function literal<S = unknown>(name: string): LiteralArgumentBuilder<S> {
|
|
39
40
|
return new LiteralArgumentBuilder(name);
|
|
40
41
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ArgumentType } from "../arguments/ArgumentType";
|
|
2
|
+
import { ArgumentCommandNode } from "../tree/ArgumentCommandNode";
|
|
3
|
+
import { ArgumentBuilder } from "./ArgumentBuilder";
|
|
2
4
|
|
|
3
5
|
export class RequiredArgumentBuilder<S, T> extends ArgumentBuilder<
|
|
4
6
|
S,
|
|
@@ -42,7 +44,7 @@ export class RequiredArgumentBuilder<S, T> extends ArgumentBuilder<
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
export function argument<S =
|
|
47
|
+
export function argument<S = unknown, T = unknown>(
|
|
46
48
|
name: string,
|
|
47
49
|
type: ArgumentType<T>,
|
|
48
50
|
): RequiredArgumentBuilder<S, T> {
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
RedirectModifier,
|
|
8
|
-
} from "..";
|
|
1
|
+
import type { RedirectModifier } from "../builder/ArgumentBuilder";
|
|
2
|
+
import type { Command } from "../Command";
|
|
3
|
+
import type { CommandNode } from "../tree/CommandNode";
|
|
4
|
+
import type { ParsedArgument } from "./ParsedArgument";
|
|
5
|
+
import type { ParsedCommandNode } from "./ParsedCommandNode";
|
|
6
|
+
import type { StringRange } from "./StringRange";
|
|
9
7
|
|
|
10
8
|
export class CommandContext<S> {
|
|
11
9
|
private source: S;
|
|
12
10
|
private input: string;
|
|
13
|
-
private arguments: Map<string, ParsedArgument<
|
|
11
|
+
private arguments: Map<string, ParsedArgument<unknown>>;
|
|
14
12
|
private nodes: ParsedCommandNode<S>[];
|
|
15
13
|
private command: Command<S>;
|
|
16
14
|
private rootNode: CommandNode<S>;
|
|
@@ -22,7 +20,7 @@ export class CommandContext<S> {
|
|
|
22
20
|
constructor(
|
|
23
21
|
source: S,
|
|
24
22
|
input: string,
|
|
25
|
-
parsedArguments: Map<string, ParsedArgument<
|
|
23
|
+
parsedArguments: Map<string, ParsedArgument<unknown>>,
|
|
26
24
|
command: Command<S>,
|
|
27
25
|
rootNode: CommandNode<S>,
|
|
28
26
|
nodes: ParsedCommandNode<S>[],
|
|
@@ -85,10 +83,10 @@ export class CommandContext<S> {
|
|
|
85
83
|
return this.rootNode;
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
get(name: string):
|
|
86
|
+
get<R = unknown>(name: string): R {
|
|
89
87
|
const argument = this.arguments.get(name);
|
|
90
88
|
// TODO: Throw exception when argument is null
|
|
91
|
-
return argument.getResult();
|
|
89
|
+
return argument.getResult() as R;
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
getRedirectModifier(): RedirectModifier<S> {
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
SuggestionContext,
|
|
11
|
-
} from "..";
|
|
1
|
+
import type { RedirectModifier } from "../builder/ArgumentBuilder";
|
|
2
|
+
import type { Command } from "../Command";
|
|
3
|
+
import type { CommandDispatcher } from "../CommandDispatcher";
|
|
4
|
+
import type { CommandNode } from "../tree/CommandNode";
|
|
5
|
+
import { CommandContext } from "./CommandContext";
|
|
6
|
+
import type { ParsedArgument } from "./ParsedArgument";
|
|
7
|
+
import { ParsedCommandNode } from "./ParsedCommandNode";
|
|
8
|
+
import { StringRange } from "./StringRange";
|
|
9
|
+
import { SuggestionContext } from "./SuggestionContext";
|
|
12
10
|
|
|
13
11
|
export class CommandContextBuilder<S> {
|
|
14
12
|
private source: S;
|
|
15
|
-
private arguments: Map<string, ParsedArgument<
|
|
13
|
+
private arguments: Map<string, ParsedArgument<unknown>>;
|
|
16
14
|
private rootNode: CommandNode<S>;
|
|
17
15
|
private dispatcher: CommandDispatcher<S>;
|
|
18
16
|
private command: Command<S>;
|
|
@@ -51,13 +49,13 @@ export class CommandContextBuilder<S> {
|
|
|
51
49
|
|
|
52
50
|
withArgument(
|
|
53
51
|
name: string,
|
|
54
|
-
argument: ParsedArgument<
|
|
52
|
+
argument: ParsedArgument<unknown>,
|
|
55
53
|
): CommandContextBuilder<S> {
|
|
56
54
|
this.arguments.set(name, argument);
|
|
57
55
|
return this;
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
getArguments(): Map<string, ParsedArgument<
|
|
58
|
+
getArguments(): Map<string, ParsedArgument<unknown>> {
|
|
61
59
|
return this.arguments;
|
|
62
60
|
}
|
|
63
61
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { StringReader } from "../StringReader";
|
|
2
|
+
import { CommandSyntaxError } from "./CommandSyntaxError";
|
|
2
3
|
|
|
3
|
-
type CommandErrorFunction = (...args:
|
|
4
|
+
type CommandErrorFunction = <A = unknown>(...args: A[]) => string;
|
|
4
5
|
|
|
5
6
|
export class CommandErrorType {
|
|
6
7
|
private func: CommandErrorFunction;
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
export * from "./Command";
|
|
2
|
-
export * from "./Predicate";
|
|
3
|
-
export * from "./context/StringRange";
|
|
4
|
-
export * from "./exceptions/CommandErrorType";
|
|
5
|
-
export * from "./exceptions/CommandSyntaxError";
|
|
6
|
-
export * from "./StringReader";
|
|
7
|
-
export * from "./suggestion/Suggestion";
|
|
8
|
-
export * from "./suggestion/Suggestions";
|
|
9
|
-
export * from "./suggestion/SuggestionsBuilder";
|
|
10
|
-
export * from "./tree/CommandNode";
|
|
11
|
-
export * from "./tree/LiteralCommandNode";
|
|
12
|
-
export * from "./tree/ArgumentCommandNode";
|
|
13
|
-
export * from "./tree/RootCommandNode";
|
|
14
1
|
export * from "./arguments/ArgumentType";
|
|
15
|
-
export * from "./arguments/
|
|
2
|
+
export * from "./arguments/BoolArgumentType";
|
|
16
3
|
export * from "./arguments/FloatArgumentType";
|
|
17
4
|
export * from "./arguments/IntegerArgumentType";
|
|
18
5
|
export * from "./arguments/LongArgumentType";
|
|
19
|
-
export * from "./arguments/
|
|
6
|
+
export * from "./arguments/NumberArgumentType";
|
|
20
7
|
export * from "./arguments/StringArgumentType";
|
|
21
8
|
export * from "./builder/ArgumentBuilder";
|
|
22
9
|
export * from "./builder/LiteralArgumentBuilder";
|
|
23
10
|
export * from "./builder/RequiredArgumentBuilder";
|
|
24
|
-
export * from "./
|
|
25
|
-
export * from "./
|
|
11
|
+
export * from "./Command";
|
|
12
|
+
export * from "./CommandDispatcher";
|
|
26
13
|
export * from "./context/CommandContext";
|
|
27
14
|
export * from "./context/CommandContextBuilder";
|
|
15
|
+
export * from "./context/ParsedArgument";
|
|
16
|
+
export * from "./context/ParsedCommandNode";
|
|
17
|
+
export * from "./context/StringRange";
|
|
28
18
|
export * from "./context/SuggestionContext";
|
|
19
|
+
export * from "./exceptions/CommandErrorType";
|
|
20
|
+
export * from "./exceptions/CommandSyntaxError";
|
|
29
21
|
export * from "./ParseResults";
|
|
30
|
-
export * from "./
|
|
22
|
+
export * from "./Predicate";
|
|
23
|
+
export * from "./StringReader";
|
|
24
|
+
export * from "./suggestion/Suggestion";
|
|
25
|
+
export * from "./suggestion/Suggestions";
|
|
26
|
+
export * from "./suggestion/SuggestionsBuilder";
|
|
27
|
+
export * from "./tree/ArgumentCommandNode";
|
|
28
|
+
export * from "./tree/CommandNode";
|
|
29
|
+
export * from "./tree/LiteralCommandNode";
|
|
30
|
+
export * from "./tree/RootCommandNode";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StringRange } from "../context/StringRange";
|
|
2
|
+
import { Suggestion } from "./Suggestion";
|
|
3
|
+
import { Suggestions } from "./Suggestions";
|
|
2
4
|
|
|
3
5
|
export class SuggestionsBuilder {
|
|
4
6
|
private input: string;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "..";
|
|
1
|
+
import type { ArgumentType } from "../arguments/ArgumentType";
|
|
2
|
+
import type { RedirectModifier } from "../builder/ArgumentBuilder";
|
|
3
|
+
import type { Command } from "../Command";
|
|
4
|
+
import type { CommandContext } from "../context/CommandContext";
|
|
5
|
+
import type { CommandContextBuilder } from "../context/CommandContextBuilder";
|
|
6
|
+
import { ParsedArgument } from "../context/ParsedArgument";
|
|
7
|
+
import type { Predicate } from "../Predicate";
|
|
8
|
+
import type { StringReader } from "../StringReader";
|
|
9
|
+
import type { Suggestions } from "../suggestion/Suggestions";
|
|
10
|
+
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
11
|
+
import { CommandNode } from "./CommandNode";
|
|
12
|
+
import CommandNodeThing from "./internal2";
|
|
14
13
|
|
|
15
14
|
export class ArgumentCommandNode<S, T> extends CommandNode<S> {
|
|
16
15
|
name: string;
|
|
17
16
|
type: ArgumentType<T>;
|
|
17
|
+
_thing: CommandNodeThing = CommandNodeThing.ARGUMENT;
|
|
18
18
|
|
|
19
19
|
constructor(
|
|
20
20
|
name: string,
|
package/src/tree/CommandNode.ts
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type Suggestions,
|
|
12
|
-
} from "..";
|
|
1
|
+
import type { ArgumentCommandNode, LiteralCommandNode } from "..";
|
|
2
|
+
import type { RedirectModifier } from "../builder/ArgumentBuilder";
|
|
3
|
+
import type { Command } from "../Command";
|
|
4
|
+
import type { CommandContext } from "../context/CommandContext";
|
|
5
|
+
import type { CommandContextBuilder } from "../context/CommandContextBuilder";
|
|
6
|
+
import type { Predicate } from "../Predicate";
|
|
7
|
+
import type { StringReader } from "../StringReader";
|
|
8
|
+
import type { Suggestions } from "../suggestion/Suggestions";
|
|
9
|
+
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
10
|
+
import CommandNodeThing from "./internal2";
|
|
13
11
|
|
|
14
12
|
export abstract class CommandNode<S> {
|
|
15
13
|
private children: Map<string, CommandNode<S>>;
|
|
16
14
|
private literals: Map<string, LiteralCommandNode<S>>;
|
|
17
|
-
private arguments: Map<string, ArgumentCommandNode<S,
|
|
15
|
+
private arguments: Map<string, ArgumentCommandNode<S, unknown>>;
|
|
18
16
|
private command: Command<S>;
|
|
19
17
|
private requirement: Predicate<S>;
|
|
20
18
|
private redirect: CommandNode<S>;
|
|
21
19
|
private modifier: RedirectModifier<S>;
|
|
22
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;
|
|
23
28
|
|
|
24
29
|
constructor(
|
|
25
30
|
command: Command<S>,
|
|
@@ -77,10 +82,13 @@ export abstract class CommandNode<S> {
|
|
|
77
82
|
});
|
|
78
83
|
} else {
|
|
79
84
|
this.children.set(node.getName(), node);
|
|
80
|
-
if (node
|
|
81
|
-
this.literals.set(node.getName(), node);
|
|
82
|
-
} else if (node
|
|
83
|
-
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
|
+
);
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
94
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "..";
|
|
1
|
+
import type { RedirectModifier } from "../builder/ArgumentBuilder";
|
|
2
|
+
import type { Command } from "../Command";
|
|
3
|
+
import type { CommandContext } from "../context/CommandContext";
|
|
4
|
+
import type { CommandContextBuilder } from "../context/CommandContextBuilder";
|
|
5
|
+
import { StringRange } from "../context/StringRange";
|
|
6
|
+
import { CommandSyntaxError } from "../exceptions/CommandSyntaxError";
|
|
7
|
+
import type { Predicate } from "../Predicate";
|
|
8
|
+
import type { StringReader } from "../StringReader";
|
|
9
|
+
import { Suggestions } from "../suggestion/Suggestions";
|
|
10
|
+
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
11
|
+
import { CommandNode } from "./CommandNode";
|
|
12
|
+
import CommandNodeThing from "./internal2";
|
|
14
13
|
|
|
15
14
|
export class LiteralCommandNode<S> extends CommandNode<S> {
|
|
16
15
|
private literal: string;
|
|
16
|
+
_thing: CommandNodeThing = CommandNodeThing.LITERAL;
|
|
17
17
|
|
|
18
18
|
constructor(
|
|
19
19
|
literal: string,
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type SuggestionsBuilder,
|
|
8
|
-
} from "..";
|
|
1
|
+
import type { CommandContext } from "../context/CommandContext";
|
|
2
|
+
import type { CommandContextBuilder } from "../context/CommandContextBuilder";
|
|
3
|
+
import type { StringReader } from "../StringReader";
|
|
4
|
+
import { Suggestions } from "../suggestion/Suggestions";
|
|
5
|
+
import type { SuggestionsBuilder } from "../suggestion/SuggestionsBuilder";
|
|
6
|
+
import { CommandNode } from "./CommandNode";
|
|
9
7
|
|
|
10
8
|
export class RootCommandNode<S> extends CommandNode<S> {
|
|
11
9
|
constructor() {
|
|
@@ -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
|
+
}
|
package/test/Arguments.test.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
argument,
|
|
3
|
-
bool,
|
|
4
3
|
CommandDispatcher,
|
|
5
4
|
FloatArgumentType,
|
|
6
5
|
IntegerArgumentType,
|
|
7
|
-
literal,
|
|
8
6
|
LongArgumentType,
|
|
7
|
+
literal,
|
|
9
8
|
} from "../src";
|
|
10
9
|
|
|
11
10
|
describe("Arguments", () => {
|
|
@@ -14,7 +13,7 @@ describe("Arguments", () => {
|
|
|
14
13
|
dispatcher.register(
|
|
15
14
|
literal("foo").then(
|
|
16
15
|
argument("bar", new IntegerArgumentType()).executes(
|
|
17
|
-
async (ctx) => ctx.get("bar") * 2,
|
|
16
|
+
async (ctx) => ctx.get<number>("bar") * 2,
|
|
18
17
|
),
|
|
19
18
|
),
|
|
20
19
|
);
|
|
@@ -27,7 +26,7 @@ describe("Arguments", () => {
|
|
|
27
26
|
dispatcher.register(
|
|
28
27
|
literal("foo").then(
|
|
29
28
|
argument("bar", new LongArgumentType()).executes(
|
|
30
|
-
async (ctx) => ctx.get("bar").toString().length,
|
|
29
|
+
async (ctx) => ctx.get<bigint>("bar").toString().length,
|
|
31
30
|
),
|
|
32
31
|
),
|
|
33
32
|
);
|