69 lines
1.7 KiB
Markdown
69 lines
1.7 KiB
Markdown
|
|
# Cómo Agregar un Nuevo Comando
|
||
|
|
|
||
|
|
**Sistema actual**: Los comandos se definen en `commands-registry.ncl` y se dispatch dinámicamente.
|
||
|
|
|
||
|
|
## Pasos para Agregar un Comando
|
||
|
|
|
||
|
|
### 1. Agregar a commands-registry.ncl
|
||
|
|
|
||
|
|
```nickel
|
||
|
|
make_command {
|
||
|
|
command = "mi-comando",
|
||
|
|
aliases = ["mi", "cmd"],
|
||
|
|
help_category = "mi-categoria", # ← Este es el domain
|
||
|
|
description = "Descripción del comando"
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
### 2. Crear módulo de handler (SI es nueva categoría)
|
||
|
|
|
||
|
|
Si `help_category = "mi-categoria"` es **nueva**, crear:
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# Archivo: provisioning/core/nulib/main_provisioning/commands/mi_categoria.nu
|
||
|
|
|
||
|
|
export def handle_mi_categoria_command [
|
||
|
|
command: string
|
||
|
|
ops: string
|
||
|
|
flags: record
|
||
|
|
] {
|
||
|
|
match $command {
|
||
|
|
"subcomando1" => { # implementar lógica aquí }
|
||
|
|
"subcomando2" => { # implementar lógica aquí }
|
||
|
|
_ => { print $"Unknown command: ($command)" }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
### 3. Importar en dispatcher.nu (SI es nueva categoría)
|
||
|
|
|
||
|
|
```nushell
|
||
|
|
# Línea ~20
|
||
|
|
use commands/mi_categoria.nu *
|
||
|
|
```
|
||
|
|
|
||
|
|
### 4. Agregar handler al registry (SI es nueva categoría)
|
||
|
|
|
||
|
|
```nushell
|
||
|
|
# Línea ~245 en handlers record
|
||
|
|
let handlers = {
|
||
|
|
infrastructure: {|cmd, ops, flags| handle_infrastructure_command $cmd $ops $flags}
|
||
|
|
orchestration: {|cmd, ops, flags| handle_orchestration_command $cmd $ops $flags}
|
||
|
|
mi-categoria: {|cmd, ops, flags| handle_mi_categoria_command $cmd $ops $flags}
|
||
|
|
}
|
||
|
|
```
|
||
|
|
|
||
|
|
## Comandos en Categoría Existente
|
||
|
|
|
||
|
|
Si `help_category` usa una categoría existente (e.g., "infrastructure"), **solo** actualizar:
|
||
|
|
|
||
|
|
1. `commands-registry.ncl` (paso 1)
|
||
|
|
2. El handler correspondiente (e.g., `commands/infrastructure.nu`)
|
||
|
|
|
||
|
|
**No** necesitas tocar dispatcher.nu.
|
||
|
|
|
||
|
|
## Resultado
|
||
|
|
|
||
|
|
✅ **1 archivo** para comando en categoría existente
|
||
|
|
✅ **3 archivos** para nueva categoría completa
|