[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/brigadier](https://jsprismarine.dev/api/@jsprismarine/brigadier/index.md) / CommandNode

# Abstract Class: CommandNode\<S\>

Defined in: [brigadier/src/tree/CommandNode.ts:15](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L15)

One node of a command tree: a literal, an argument or the root, with its children.

## Extended by

- [`ArgumentCommandNode`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/ArgumentCommandNode.md)
- [`LiteralCommandNode`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/LiteralCommandNode.md)
- [`RootCommandNode`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/RootCommandNode.md)

## Type Parameters

### S

`S`

## Constructors

### Constructor

> **new CommandNode**\<`S`\>(`command`, `requirement`, `redirect`, `modifier`, `forks`): `CommandNode`\<`S`\>

Defined in: [brigadier/src/tree/CommandNode.ts:35](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L35)

#### Parameters

##### command

[`Command`](https://jsprismarine.dev/api/@jsprismarine/brigadier/index.md#command)\<`S`\> \| `null`

##### requirement

[`Predicate`](https://jsprismarine.dev/api/@jsprismarine/brigadier/index.md#predicate)\<`S`\> \| `null`

##### redirect

`CommandNode`\<`S`\> \| `null`

##### modifier

[`RedirectModifier`](https://jsprismarine.dev/api/@jsprismarine/brigadier/index.md#redirectmodifier)\<`S`\> \| `null`

##### forks

`boolean`

#### Returns

`CommandNode`\<`S`\>

## Methods

### addChild()

> **addChild**(`node`): `void`

Defined in: [brigadier/src/tree/CommandNode.ts:85](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L85)

Adds a child, merging it into an existing child of the same name. Throws for a root node.

#### Parameters

##### node

`CommandNode`\<`S`\>

#### Returns

`void`

***

### canUse()

> **canUse**(`source`): `boolean`

Defined in: [brigadier/src/tree/CommandNode.ts:80](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L80)

Returns whether `source` passes the node's requirement.

#### Parameters

##### source

`S`

#### Returns

`boolean`

***

### compareTo()

> **compareTo**(`o`): `number`

Defined in: [brigadier/src/tree/CommandNode.ts:201](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L201)

Orders literals before arguments, and nodes of one kind by their sorted keys.

#### Parameters

##### o

`CommandNode`\<`S`\>

#### Returns

`number`

***

### createBuilder()

> `abstract` **createBuilder**(): [`ArgumentBuilder`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/ArgumentBuilder.md)\<`S`, `any`\>

Defined in: [brigadier/src/tree/CommandNode.ts:174](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L174)

Returns a builder that builds a copy of the node.

#### Returns

[`ArgumentBuilder`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/ArgumentBuilder.md)\<`S`, `any`\>

***

### equals()

> **equals**(`o`): `boolean`

Defined in: [brigadier/src/tree/CommandNode.ts:141](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L141)

Returns whether `o` is a node with equal children and an equal command.

#### Parameters

##### o

`object`

#### Returns

`boolean`

***

### findAmbiguities()

> **findAmbiguities**(`consumer`, `context`): `void`

Defined in: [brigadier/src/tree/CommandNode.ts:113](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L113)

Reports each pair of sibling nodes, at any depth, that accept the same example input.

#### Parameters

##### consumer

[`AmbiguityConsumer`](https://jsprismarine.dev/api/@jsprismarine/brigadier/index.md#ambiguityconsumer)\<`S`\>

##### context

`any`

#### Returns

`void`

***

### getChild()

> **getChild**(`name`): `CommandNode`\<`S`\> \| `undefined`

Defined in: [brigadier/src/tree/CommandNode.ts:65](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L65)

Returns the child with the given name, if there is one.

#### Parameters

##### name

`string`

#### Returns

`CommandNode`\<`S`\> \| `undefined`

***

### getChildren()

> **getChildren**(): `MapIterator`\<`CommandNode`\<`S`\>\>

Defined in: [brigadier/src/tree/CommandNode.ts:55](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L55)

Returns the child nodes, literals before arguments.

#### Returns

`MapIterator`\<`CommandNode`\<`S`\>\>

***

### getChildrenCount()

> **getChildrenCount**(): `number`

Defined in: [brigadier/src/tree/CommandNode.ts:60](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L60)

Returns how many children the node has.

#### Returns

`number`

***

### getCommand()

> **getCommand**(): [`Command`](https://jsprismarine.dev/api/@jsprismarine/brigadier/index.md#command)\<`S`\> \| `null`

Defined in: [brigadier/src/tree/CommandNode.ts:50](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L50)

Returns the command the node runs, or null when the input cannot end on it.

#### Returns

[`Command`](https://jsprismarine.dev/api/@jsprismarine/brigadier/index.md#command)\<`S`\> \| `null`

***

### getExamples()

> `abstract` **getExamples**(): `Iterable`\<`string`\>

Defined in: [brigadier/src/tree/CommandNode.ts:215](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L215)

Returns sample inputs the node accepts, for finding ambiguities.

#### Returns

`Iterable`\<`string`\>

***

### getName()

> `abstract` **getName**(): `string`

Defined in: [brigadier/src/tree/CommandNode.ts:162](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L162)

Returns the node's name, which is unique among its siblings.

#### Returns

`string`

***

### getNodeType()

> `abstract` **getNodeType**(): `string`

Defined in: [brigadier/src/tree/CommandNode.ts:33](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L33)

Returns the kind of node: `literal`, `argument` or `root`.

#### Returns

`string`

***

### getRedirect()

> **getRedirect**(): `CommandNode`\<`S`\> \| `null`

Defined in: [brigadier/src/tree/CommandNode.ts:70](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L70)

Returns the node the input is redirected to, or null.

#### Returns

`CommandNode`\<`S`\> \| `null`

***

### getRedirectModifier()

> **getRedirectModifier**(): [`RedirectModifier`](https://jsprismarine.dev/api/@jsprismarine/brigadier/index.md#redirectmodifier)\<`S`\> \| `null`

Defined in: [brigadier/src/tree/CommandNode.ts:75](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L75)

Returns the modifier applied to the source on a redirect, or null.

#### Returns

[`RedirectModifier`](https://jsprismarine.dev/api/@jsprismarine/brigadier/index.md#redirectmodifier)\<`S`\> \| `null`

***

### getRelevantNodes()

> **getRelevantNodes**(`input`): `Iterable`\<`CommandNode`\<`S`\>\>

Defined in: [brigadier/src/tree/CommandNode.ts:180](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L180)

Returns the children worth trying for the next word: the literal it names, or else every argument.

#### Parameters

##### input

[`StringReader`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/StringReader.md)

#### Returns

`Iterable`\<`CommandNode`\<`S`\>\>

***

### getRequirement()

> **getRequirement**(): [`Predicate`](https://jsprismarine.dev/api/@jsprismarine/brigadier/index.md#predicate)\<`S`\>

Defined in: [brigadier/src/tree/CommandNode.ts:157](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L157)

Returns the predicate a source must pass to use the node.

#### Returns

[`Predicate`](https://jsprismarine.dev/api/@jsprismarine/brigadier/index.md#predicate)\<`S`\>

***

### getSortedKey()

> `abstract` **getSortedKey**(): `string`

Defined in: [brigadier/src/tree/CommandNode.ts:177](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L177)

Returns the key the node sorts by among siblings of the same kind.

#### Returns

`string`

***

### getUsageText()

> `abstract` **getUsageText**(): `string`

Defined in: [brigadier/src/tree/CommandNode.ts:165](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L165)

Returns how the node appears in a usage string.

#### Returns

`string`

***

### isFork()

> **isFork**(): `boolean`

Defined in: [brigadier/src/tree/CommandNode.ts:210](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L210)

Returns whether the redirect runs once for each source the modifier returns.

#### Returns

`boolean`

***

### isValidInput()

> `abstract` **isValidInput**(`input`, `context`): `boolean`

Defined in: [brigadier/src/tree/CommandNode.ts:138](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L138)

Returns whether the node accepts `input`.

#### Parameters

##### input

`string`

##### context

`any`

#### Returns

`boolean`

***

### listSuggestions()

> `abstract` **listSuggestions**(`context`, `builder`): `Promise`\<[`Suggestions`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/Suggestions.md)\>

Defined in: [brigadier/src/tree/CommandNode.ts:171](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L171)

Returns the completions the node offers for the input.

#### Parameters

##### context

[`CommandContext`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/CommandContext.md)\<`S`\>

##### builder

[`SuggestionsBuilder`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/SuggestionsBuilder.md)

#### Returns

`Promise`\<[`Suggestions`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/Suggestions.md)\>

***

### parse()

> `abstract` **parse**(`reader`, `contextBuilder`): `void`

Defined in: [brigadier/src/tree/CommandNode.ts:168](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/brigadier/src/tree/CommandNode.ts#L168)

Parses the node's part of the input into the context. Throws on input the node rejects.

#### Parameters

##### reader

[`StringReader`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/StringReader.md)

##### contextBuilder

[`CommandContextBuilder`](https://jsprismarine.dev/api/@jsprismarine/brigadier/classes/CommandContextBuilder.md)\<`S`\>

#### Returns

`void`
