2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-13 16:56:33 +00:00
bench/docs/bench_custom_cmd.md
Ankush Menat b51f0ed2b2
feat: bench setup requirements --dev (#1196)
* chore: typo

* chore: update project description

* feat: command to install dev-requirements.txt

Often applications have development or test specific requirements which
are not required in production.

- Add new command `bench setup dev-requirements`
- installs all `dev-requirements.txt` in app's root folder.

* refactor: remove duplicate function

* refactor: use `log` instead of print

* refactor: merge dev-requirement command

* feat: install dev-dependencies in get-app if dev

When developer mode is enabled install all dev dependencies too while
doing `get-app`

* fix: warn about --dev not supporting node
2021-09-13 20:55:21 +05:30

1.9 KiB

How are Frappe Framework commands available via bench?

bench utilizes frappe.utils.bench_manager to get the framework's as well as those of any custom commands written in application installed in the Frappe environment. Currently, with version 12 there are commands related to the scheduler, sites, translations and other utils in Frappe inherited by bench.

Can I add CLI commands in my custom app and call them via bench?

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 checks 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 may be visualized as:

frappe-bench
|──apps
    |── frappe
    ├── custom_app
    │   ├── README.md
    │   ├── custom_app
    │   │   ├── 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', 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 context of the current bench, this command maybe executed simply as

➜ bench set-flags
Flags are set to state: 'on'