command:create

Introduction

command:create writes the skeleton of a new CLI command in splent_cli/src/splent_cli/commands/, with its Click decorator and the cli_command export. Use it as the starting point for a command you add to splent_cli.

splent command:create db:dump-all
Does this command require access to the Flask app context? [y/N]: n
✅ Command 'db:dump-all' created at: /workspace/splent_cli/src/splent_cli/commands/db_dump_all.py

A command that needs the app

Answer y to the question. The skeleton is then decorated with @requires_app and imports current_app, so the CLI builds the active product’s app before running it.


Naming the command

The name is lowercased and has at most one :, as in db:dump-all. Each side starts with a letter and uses only letters, digits, _ and -.

The command keeps the name. The file and the function replace : and - with _, so db:dump-all becomes db_dump_all.py.

Python keywords and the names click, current_app and requires_app, which the generated module uses, are refused.


Reference

Error When
Error: Invalid command name '<name>'. Use lowercase letters, digits, '_' and '-', starting with a letter, and at most one ':' (for example db:dump-all). Python keywords and the names click, current_app and requires_app are not allowed. The name breaks the rules above. It fails before the question
Error: The command '<name>' already exists as file <file>. The file exists. Nothing is written

Back to top

splent. Distributed by an LGPL license v3. Contact us: drorganvidez@us.es