I create a lib which can be imported and used as is, and there is also a start script, which creates a single instance of the main class for use within the script:
# read config, init stuff, and then create an instance
r = RepoClient(config)
Now, the start script accepts a 'command' argument, and as of now, it must be invoke like:
repo config.json -c 'r.ls()'
i.e. the 'r' variable must be used.
I would like to be able to drop the 'r' variable. For that, the start script, somehow, needs the ls
function. I can do it by putting the following in the script, after the r
instance is created:
ls = r.ls
etc. for all the commands the RepoClient class supports.
Is there anything automatic? The code below doesn't work, of course, but you get the idea:
from r import *
What I can think of is annotating methods with a custom @command
annotation, iterating over all the methods and checking for it and if found, setting it as a script global, but hopefully the batteries do support something like this already ;d
EDIT: for now, the command passed as the last argument is run the following way:
exec(sys.argv[2])