How do you create and test a custom command with the Flask CLI?

Instruction: Use Flask’s built-in CLI to implement a complete non-destructive database initialization example. Show invocation, argument validation, explicit failure behavior, and how to test the command.

Context: Assesses Flask CLI registration, application context, Click options, database error propagation, and command testing.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

For current Flask, use its built-in Click-based CLI. Flask-Script is a legacy extension; a Manager(app) declaration alone is not an executable command entry point. With Flask's CLI, registering a command on app.cli also supplies an application context.

Save this complete Flask 3.x example as app.py...

Related Questions