Is there a way to make a python click cli that can dynamically grow and adjust without having to touch the code (i.e., new commands can be added)? Let me explain. In a database, users update "jobs" with options (arguments). The cli will then access this database, read the data, and using click functionality dynamically add these options to existing decorated functions in the code. It works great. This means I only need to update the database and then the cli automatically reflects those changes (--help works great, etc.). This allows me to adjust the functionality of existing commands in the database.
The cli serves as an api front-end, so the logic to handle the commands resides outside of the code with a listening service. The cli just needs to get the command, options, arguments, etc., together (validated, correctly organized, etc.) and send it off for processing.
@cli.command('c1')
@click.pass_context
def command1(ctx):
...
@cli.command('c2')
@click.pass_context
def command2(ctx):
...
etc.
All of these commands work with the DefaultGroup Class.
The option list for each command is different and sometimes long. And because the options were needed in the database anyway, why put them in two places (the code and the database) that potentially could get out of sync.
The next step is to make it so I don't ever have to touch the cli code again. When new commands are requested, I need to visit the code, create a new function, decorate it, and put the database arguments in so the code can work as expected. I don't want to do that anymore. Since most of the commands are http-based (requests sent off to an application that handles the work), I would hope that having a single dynamically decorated function would be possible.
I would love to be able to get to the point where I update the database with a new command's arguments, and then just run the cli and it automatically works ... no code changes. I don't have to tell the cli about the new command or anything. It reads the database, finds the command, decorates the function with the found options/arguments, etc., and works as expected.
I've looked into creating a customized multi-command class. But for that I would need to know the command names beforehand (which I don't). However, worst-case scenario is that I use an updated list of commands (i.e., these 15 commands route to a single function [1,2,3...15]). Then I would need to update the list when new commands are added (which isn't too terrible, but still).
I've looked into dynamically creating command-handling functions on the fly for each command ... but decorating dynamically created functions may be a bit of a challenge.
Is this nirvana even possible?