jdx / usage

A specification for CLIs
https://usage.jdx.dev
MIT License
138 stars 6 forks source link

discussion - self-completing commends #5

Open akdor1154 opened 9 months ago

akdor1154 commented 9 months ago

heya,

this looks fab! One thing I've been wondering about is some sort of self-documenting/completing mechanism - e.g. some way for bins/scripts to act as their own completer.

having a way to get a usage spec out of a script/bin (e.g. your double-shebang mechanism) is one half, but the other is for the command itself to be recursively involved in completions. Think e.g. a field that wants an s3:// url, or an scp remotehost:/remotepath field. Not fleshed out sorry, I'll come back to this :)

jdx commented 9 months ago

yes, this is table-stakes. In fact what I need usage for currently is the ability to "mount" one CLI into another for mise run .... I haven't fully figured out how this will work but right now but in usage-cli I'm thinking the commands to build completions and stuff could accept a command string, e.g.:

$ usage complete-word -x "mycli --usage"

And it would exec mycli --usage, get the dynamic definition, and be able to complete against it.

But it may make sense to configure this by putting it into the spec itself, maybe we could add a param like this:

fetch_spec "mycli --usage"

I don't love that name but something like that.