Back to Skills

cli-module

verified

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 GitHub

Marketplace

myfy-plugins

psincraian/myfy

Plugin

myfy

frameworks

Repository

psincraian/myfy
83stars

plugins/claude-code/skills/cli-module/SKILL.md

Last Verified

January 20, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/psincraian/myfy/blob/main/plugins/claude-code/skills/cli-module/SKILL.md -a claude-code --skill cli-module

Installation paths:

Claude
.claude/skills/cli-module/
Powered by add-skill CLI

Instructions

# 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

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
5802 chars