CLI - Usage guide¶
Using built-in commands¶
Start development server¶
Database operations¶
Translation management¶
Adding custom commands¶
Simple command¶
Create a command in any module that gets imported:
from fastedgy.cli import command, option, pass_cli_context, CliContext
@command()
@option("--name", default="World", help="Name to greet")
@pass_cli_context
def hello(ctx: CliContext, name: str):
"""Say hello to someone."""
from fastedgy.cli import console
console.print(f"[green]Hello, {name}![/green]")
Command with group¶
Create commands organized in groups:
from fastedgy.cli import group, command, option, pass_cli_context, CliContext
@group()
def data():
"""Data management commands."""
pass
@data.command()
@option("--format", default="json", help="Output format")
@pass_cli_context
def export(ctx: CliContext, format: str):
"""Export application data."""
from fastedgy.cli import console
console.print(f"[blue]Exporting data in {format} format...[/blue]")
Rich output¶
Use Rich components for beautiful terminal output:
from fastedgy.cli import command, pass_cli_context, CliContext, console, Table
@command()
@pass_cli_context
def status(ctx: CliContext):
"""Show application status."""
table = Table(title="Application Status")
table.add_column("Component", style="cyan")
table.add_column("Status", style="green")
table.add_row("Database", "Connected")
table.add_row("Cache", "Active")
table.add_row("Queue", "Running")
console.print(table)
Command discovery¶
Commands are automatically discovered when:
- Module import: The module containing your command is imported
- Decorator usage: Commands use the
@command()
decorator - Group registration: Commands are part of a
@group()
Access services¶
Use the CLI context to access application services:
@command()
@pass_cli_context
async def migrate(ctx: CliContext):
"""Run database migrations."""
# Access settings
settings = ctx.get(BaseSettings)
# Access FastEdgy app and services
app = await ctx.get_app()
# Your migration logic here