# Registering Feature Commands

This guide shows how to expose commands from a feature using the OMS command system.

The example extends `HelloWorldFeature` with a simple command that prints a message to the console.

***

### Overview

Features can expose commands by overriding `additionalCommands`.

These commands are automatically registered under:

```
/oms feature <feature_id> ...
```

***

### 1. Create a command entry

Commands are defined by extending `OMSCommandEntry`.

```kotlin
class HelloWorldPrintCommand(
    private val feature: HelloWorldFeature
) : OMSCommandEntry() {

    override fun init(): ArgumentBuilder<CommandSourceStack, *> {
        return Commands.literal("print")
            .executes { ctx ->
                val source = ctx.source
                val server = source.server
                server.playerList.broadcastSystemMessage(
                    Component.literal(
                        feature.config.message()
                    ),
                    false
                )
                1
            }
    }
}
```

This defines:

* command name: `print`
* execution logic: print message from config

***

### 2. Attach command to the feature

Override `additionalCommands` in your feature:

```kotlin
class HelloWorldFeature(
    configProvider: ConfigProvider<CHelloWorldFeature>
) : OmsFeature<CHelloWorldFeature>(configProvider) {

    override val additionalCommands = listOf(
        HelloWorldPrintCommand(this)
    )
    
}
```

***

### 3. Use the command

After startup, the command will be available under:

```
/oms feature hello_world print
```

***

### Notes

* Commands are defined using Brigadier
* Features expose commands via `additionalCommands`
* Command structure is hierarchical
* Commands are registered automatically by OMS


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://conboi.gitbook.io/oms-wiki/developer-guide/implementation-guides/registering-feature-commands.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
