Python commands is a light-weight, django-admin inspired, CLI Command tool.
pip install nci-python-commands
manage
manage
manage my-command-name
- Create File
You can create a blank command by typing the following:
manage create_command
- Example Code
In print_my_number.py:
from commandable import Command
class PrintMyNumber(Command):
description = "A description of your command"
def __init__(self, args=None):
self.register_argument(
"-v",
nargs='?',
const=True,
type=bool,
description="Verbose output"
)
self.register_argument(
"--mynumber",
description="What is your number?",
default=2,
type=int
)
super().__init__(args)
def command(self, **kwargs):
# Place your command code here
if self.get("v"):
print("Verbose mode is on")
print("Your lucky number is: {}".format(self.get("mynumber"))) #Your lucky number is: 2
class PrintMyNumber(Command):
description = "A description of your command"
hidden = True
...
In the section Commands
add the module names that need to be scanned for commands and add a readable name as value.
Commands:
modulename: "module.path"
downloaddata: "download.data"
importers: "import_data"