Bench - Extending the CLI
Along with the framework commands, Frappe's bench\_manager
module also searches
for any commands in your custom applications. Thereby, bench communicates with
the respective bench's Frappe which in turn will check for available commands in
all of the applications.
To make your custom command available to bench, just create a commands
module
under your parent module and write the command with a click wrapper and a
variable commands which contains a list of click functions, which are your own
commands.
The directory structure with a Frappe App flags
may be visualized as:
frappe-bench
|──apps
|── frappe
├── flags
│ ├── README.md
│ ├── flags
│ │ ├── commands <------ commands module
│ ├── license.txt
│ ├── requirements.txt
│ └── setup.py
The commands module maybe a single file such as commands.py
or a directory
with an \_\_init\_\_.py
file. For a custom application of name 'flags', an example
may be given as
# file\_path: frappe-bench/apps/flags/flags/commands.py
import click
@click.command('set-flags')
@click.argument('state', type=click.Choice(['on', 'off']))
def set\_flags(state):
from flags.utils import set\_flags
set\_flags(state=state)
commands = [
set\_flags
]
and with the context of the current bench, this command maybe executed simply as
➜ bench set-flags
Flags are set to state: 'on'