Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.

fix: fix cli decorators and creation #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion project_name/ext/commands.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import click

from flask.cli import with_appcontext
from project_name.ext.auth import create_user
from project_name.ext.database import db
from project_name.models import Product


@click.command("create_db")
@with_appcontext
def create_db():
"""Creates database"""
db.create_all()


@click.command("drop_db")
@with_appcontext
def drop_db():
"""Cleans database"""
db.drop_all()


@click.command("populate_db")
@with_appcontext
def populate_db():
"""Populate db with sample data"""
data = [
Expand All @@ -32,7 +39,7 @@ def populate_db():
def init_app(app):
# add multiple commands in a bulk
for command in [create_db, drop_db, populate_db]:
app.cli.add_command(app.cli.command()(command))
app.cli.add_command(command)

# add a single command
@app.cli.command()
Expand Down