flux-framework / flux-core

core services for the Flux resource management framework
GNU Lesser General Public License v3.0
165 stars 49 forks source link

add completion/introspection helper to liboptparse #4953

Open grondo opened 1 year ago

grondo commented 1 year ago

It would be nice if liboptparse had an introspection or completion helper option that let a caller query the subcommands and options available in a Flux command using optparse. Not only would this allow completions to be easily kept up-to-date, but would also be helpful in making a suggestion system for flux, e.g. if a user types flux kill JOBID, they might get kill is not a flux command. Try flux job kill or similar.

@trws mentioned an existing solution for argparse. We could make a compatible solution for optparse.

trws commented 1 year ago

There are a couple, one of the best known is probably https://kislyuk.github.io/argcomplete/, though I am not sure that has a convenient way to export the completions, it can do completion for essentially any argparse-based program. This one is newer (I think) and I haven't actually used it, but I've heard great things and it can actually generate scripts we can install rather than doing it dynamically: https://github.com/iterative/shtab

trws commented 1 year ago

I actually think a decent way to do this might be to write a little python wrapper that can load all the optparse definitions from a C library and just run them through shtab. That way we only have to learn one generator and write one conversion of a format we know well rather than having to come up with something new from whole cloth.

grondo commented 1 year ago

Great idea!