prvng_core/nulib/main_provisioning/ADDING_COMMANDS.md

69 lines
1.7 KiB
Markdown
Raw Normal View History

feat(core): three-layer DAG, unified component arch, commands-registry cache, Nushell 0.112.2 migration - DAG architecture: `dag show/validate/export` (nulib/main_provisioning/dag.nu), config loader (lib_provisioning/config/loader/dag.nu), taskserv dag-executor. Backed by schemas/lib/dag/*.ncl; orchestrator emits NATS events via WorkspaceComposition::into_workflow. See ADR-020, ADR-021. - Unified Component Architecture: components/mod.nu, main_provisioning/ {components,workflow,extensions,ontoref-queries}.nu. Full workflow engine with topological sort and NATS subject emission. Blocks A-H complete (libre-daoshi). - Commands-registry: nulib/commands-registry.ncl (Nickel source, 314 lines) + JSON cache at ~/.cache/provisioning/commands-registry.json rebuilt on source change. cli/provisioning fast-path alias expansion avoids cold Nu startup. ADDING_COMMANDS.md documents new-command workflow. - Platform service manager: service-manager.nu (+573), startup.nu (+611), service-check.nu (+255); autostart/bootstrap/health/target refactored. - Nushell 0.112.2 migration: removed all try/catch and bash redirections; external commands prefixed with ^; type signatures enforced. Driven by scripts/refactor-try-catch{,-simplified}.nu. - TTY stack: removed shlib/*-tty.sh; replaced by cli/tty-dispatch.sh, tty-filter.sh, tty-commands.conf. - New domain modules: images/ (golden image lifecycle), workspace/{state,sync}.nu, main_provisioning/{bootstrap,cluster-deploy,fip,state}.nu, commands/{state, build,integrations/auth,utilities/alias}.nu, platform.nu expanded (+874). - Config loader overhaul: loader/core.nu slimmed (-759), cache/core.nu refactored (-454), removed legacy loaders/file_loader.nu (-330). - Thirteen new provisioning-<domain>.nu top-level modules for bash dispatcher. - Tests: test_workspace_state.nu (+351); updates to test_oci_registry, test_services. - README + CHANGELOG updated.
2026-04-17 04:27:33 +01:00
# 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