Closed Jaymon closed 4 months ago
So the main file would be similar to an asgi or wsgi entry file with the addition of the if __name__
block:
from captain import Application
application = Application()
if __name__ == "__main__":
application()
Then you can put all your commands in a commands
module. The commands
module will work exactly like endpoints's controllers
. So Captain and Endpoints will basically work the exact same except one would be for http requests and the other would be for CLI requests.
Once I've got the new functionality in I think I should have a SimpleApplication
that is the default, which is the current/old functionality. And then a ComplexApplication
that contains all the new autoloading and submodule commands. The ComplexApplication
is designed for primary command line interfaces with multiple subcommands while the SimpleApplication
is for a simple script.
Rather than have simple and complex be explicit. I think I can have Application determine it, if there are already defined commands, then assume it's a simple command. If there aren't, then check for prefixes or autodiscover. If prefixes are explicitely passed in then load those. I think this covers all the bases with just the Application
class
I could do something similar to Endpoints and have a commands prefix:
And if
commands/bar/che.py
could have:And then on the command line:
would call
commands.bar.che.Boom(**{"one": ["1"], "two": ["2"]})
.In this way I could do arbitrary nested subcommands.