If your CLI has dynamic subcommands (e.g., a run command that executes tasks with varying arguments), you can use the mount property to inject usage specifications at runtime.
To implement this:
- Create a hidden command (e.g.,
mycli mount-usage-tasks) that, when executed, emits a KDL usage spec describing the dynamic tasks. - Define a
mount on the parent command in your static spec, pointing to that hidden command.
When a user triggers completion (e.g., mycli run <tab><tab>), the system executes the mount command and merges its output into the run command's specification.
Execution Note: Mounts are executed via sh -c (falling back to cmd /c on Windows). If your mount points to a shebang script, a POSIX shell must be available on the PATH.
// Static usage spec
cmd "mount-usage-tasks" hide=#true
cmd "run" {
mount run="mycli mount-usage-tasks"
}
// Example of what the mount command might emit:
cmd "task1" {
arg "arg1" help="task1 arg1"
flag "flag1" help="task1 flag1"
}
cmd "task2" {
arg "arg1" help="task2 arg1"
flag "flag1" help="task2 flag1"
}