Wake

The main use case for wake() has been covered in the introductory tutorial. Specifically, after all commands have been register()ed, wake() is used to wake from a coma.

An additional use case is simulating command line arguments using args and namespace, which are simply passed to ArgumentParser.parse_known_args():

main.py
import coma

if __name__ == "__main__":
    coma.register("greet", lambda: print("Hello World!"))
    coma.wake(["greet"])

Running this program without providing command line arguments works because wake() is simulating greet as a command line argument:

$ python main.py
Hello World!

Finally, wake() raises a WakeException when encountering a waking problem. The main use case is to simply leave the exception unhandled as it gives useful warnings (e.g., about missing command line arguments). A more advanced use case involves catching the exception to wake with a default command:

main.py
import coma

if __name__ == "__main__":
    coma.register("greet", lambda: print("Hello World!"))
    coma.register("default", lambda: print("Default command."))
    try:
        coma.wake()
    except coma.WakeException:
        coma.wake(["default"])

Running this program without providing command line arguments simulates running with default as a command line argument:

$ python main.py greet
Hello World!
$ python main.py
Default command.