In glim, there is a command line utility layer where you can define command line apps that can be run from terminal. In a typical glim app, all command line apps reside in app/commands.py. In this file, all commands are extended from Command class in glim.command module.

This command layer uses ArgumentParser object of argparse module. Consider the examples of Hello & Greet commands. Hello command just prints "Hello World!" and Greet command takes an user name argument prints "hello :name";

# commands.py from glim.command import Command class HelloCommand(Command): name = 'hello' description = 'prints hello world' def configure(self): pass def run(self): print("Hello World!") pass class GreetCommand(Command): name = 'greet' description = 'greets a user' def configure(self): self.add_argument("name", nargs='?', help="enter project name", default=None) def run(self): print("Hello %s!" % self.args.name)

These commands are automatically registered when you run glim from command line. The following outputs will be appeared on glim commands;

$ glim hello Hello World! $ glim greet aras Hello Aras!

In a typical Command, self.add_argument(*args, **kwargs) would create an argument using ArgumentParser. You can see more examples of argument adding here.

🚧

Register arguments in only configure function

You can only register arguments inside the configure function.


Did this page help you?