myfy CliModule for custom CLI commands with DI injection. Use when working with CliModule, @cli.command decorator, command groups, CLI arguments, CLI options, or myfy app commands.
View on GitHubSelect agents to install to:
npx add-skill https://github.com/psincraian/myfy/blob/main/plugins/claude-code/skills/cli-module/SKILL.md -a claude-code --skill cli-moduleInstallation paths:
.claude/skills/cli-module/# CliModule - Custom CLI Commands
CliModule enables custom CLI commands with full dependency injection and Typer integration.
## Quick Start
```python
from myfy.core import Application
from myfy.commands import CliModule, cli
@cli.command()
async def seed_users(user_service: UserService, count: int = 10):
'''Seed the database with test users.'''
for i in range(count):
await user_service.create(f"user{i}@example.com")
print(f"Created {count} users")
app = Application()
app.add_module(CliModule())
# Run with: myfy app seed-users --count 20
```
## Configuration
Environment variables use the `MYFY_CLI_` prefix:
| Variable | Default | Description |
|----------|---------|-------------|
| `MYFY_CLI_VERBOSE` | `False` | Enable verbose output |
| `MYFY_CLI_NO_COLOR` | `False` | Disable colored output |
| `MYFY_CLI_TIMEOUT` | `300` | Command timeout (seconds) |
## Defining Commands
### Basic Command
```python
from myfy.commands import cli
@cli.command()
async def hello():
'''Say hello.'''
print("Hello, World!")
# Run: myfy app hello
```
### With DI Injection
Services are automatically injected:
```python
from myfy.commands import cli
from myfy.data import AsyncSession
@cli.command()
async def count_users(session: AsyncSession):
'''Count users in the database.'''
result = await session.execute(select(func.count(User.id)))
count = result.scalar()
print(f"Total users: {count}")
# Run: myfy app count-users
```
### With Arguments
```python
@cli.command()
async def greet(name: str):
'''Greet someone by name.'''
print(f"Hello, {name}!")
# Run: myfy app greet John
```
### With Options
```python
@cli.command()
async def seed(count: int = 10, verbose: bool = False):
'''Seed the database.'''
for i in range(count):
if verbose:
print(f"Creating user {i + 1}/{count}")
await create_user(i)
print(f"Created {count} users")
# Run: myfy app seed --count 50 --verbose
```
## Comma