{"_id":"553d394e9660ba0d00569d1c","category":{"_id":"553d394d9660ba0d00569d08","pages":["553d394e9660ba0d00569d13","553d394e9660ba0d00569d14","553d394e9660ba0d00569d15","553d394e9660ba0d00569d16","553d394e9660ba0d00569d17","553d394e9660ba0d00569d18","553d394e9660ba0d00569d19","553d394e9660ba0d00569d1a","553d394e9660ba0d00569d1b","553d394e9660ba0d00569d1c","553d394e9660ba0d00569d1d","553d394e9660ba0d00569d1e","553d394e9660ba0d00569d1f","553d394e9660ba0d00569d20","553d394e9660ba0d00569d21","553d394e9660ba0d00569d22","553d394e9660ba0d00569d23"],"project":"543467200ef9c00800164ecc","version":"553d394d9660ba0d00569d07","__v":1,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-10-15T18:00:23.862Z","from_sync":false,"order":0,"slug":"glim","title":"GLIM"},"__v":0,"user":"543466ea0e8e2b0e00341818","project":"543467200ef9c00800164ecc","version":{"_id":"553d394d9660ba0d00569d07","project":"543467200ef9c00800164ecc","forked_from":"54bedb2fffb79c320030db1f","__v":1,"createdAt":"2015-04-26T19:15:25.245Z","releaseDate":"2015-04-26T19:15:25.245Z","categories":["553d394d9660ba0d00569d08","553d394d9660ba0d00569d09"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"0.11.2","version":"0.11.2"},"githubsync":"","metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-10-15T18:24:26.256Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"never","params":[],"url":""},"isReference":false,"order":7,"body":"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.\n\nThis 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\";\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"# commands.py\\nfrom glim.command import Command\\n\\nclass HelloCommand(Command):\\n  \\tname = 'hello'\\n    description = 'prints hello world'\\n\\t\\tdef configure(self):\\n\\t\\t\\t\\tpass\\n \\t\\tdef run(self):\\n      \\tprint(\\\"Hello World!\\\")\\n\\t\\t    pass\\n      \\nclass GreetCommand(Command):\\n  \\tname = 'greet'\\n    description = 'greets a user'\\n    def configure(self):\\n\\t\\t\\t\\tself.add_argument(\\\"name\\\", nargs='?',\\n                          help=\\\"enter project name\\\",\\n                          default=None)\\n    def run(self):\\n      \\tprint(\\\"Hello %s!\\\" % self.args.name)\\n  \",\n      \"language\": \"python\"\n    }\n  ]\n}\n[/block]\nThese commands are automatically registered when you run `glim` from command line. The following outputs will be appeared on glim commands;\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ glim hello\\nHello World!\\n\\n$ glim greet aras\\nHello Aras!\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nIn a typical Command, `self.add_argument(*args, **kwargs)` would create an argument using `ArgumentParser`. You can see more examples of argument adding [here](https://docs.python.org/2/library/argparse.html). \n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Register arguments in only configure function\",\n  \"body\": \"You can only register arguments inside the configure function.\"\n}\n[/block]","excerpt":"","slug":"commands","type":"basic","title":"Commands"}
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"; [block:code] { "codes": [ { "code": "# commands.py\nfrom glim.command import Command\n\nclass HelloCommand(Command):\n \tname = 'hello'\n description = 'prints hello world'\n\t\tdef configure(self):\n\t\t\t\tpass\n \t\tdef run(self):\n \tprint(\"Hello World!\")\n\t\t pass\n \nclass GreetCommand(Command):\n \tname = 'greet'\n description = 'greets a user'\n def configure(self):\n\t\t\t\tself.add_argument(\"name\", nargs='?',\n help=\"enter project name\",\n default=None)\n def run(self):\n \tprint(\"Hello %s!\" % self.args.name)\n ", "language": "python" } ] } [/block] These commands are automatically registered when you run `glim` from command line. The following outputs will be appeared on glim commands; [block:code] { "codes": [ { "code": "$ glim hello\nHello World!\n\n$ glim greet aras\nHello Aras!", "language": "shell" } ] } [/block] In a typical Command, `self.add_argument(*args, **kwargs)` would create an argument using `ArgumentParser`. You can see more examples of argument adding [here](https://docs.python.org/2/library/argparse.html). [block:callout] { "type": "warning", "title": "Register arguments in only configure function", "body": "You can only register arguments inside the configure function." } [/block]