Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions src/pumpfun_cli/commands/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,29 @@ def _display_tokens(ctx: typer.Context, tokens: list[dict]):


@app.command("trending")
def trending(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n")):
def trending(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n", min=1)):
"""Top runners + recommended tokens."""
tokens = asyncio.run(get_trending_tokens(limit=limit))
_display_tokens(ctx, tokens)


@app.command("new")
def new(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n")):
def new(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n", min=1)):
"""Recently launched tokens."""
tokens = asyncio.run(get_new_tokens(limit=limit))
_display_tokens(ctx, tokens)


@app.command("graduating")
def graduating(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n")):
def graduating(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n", min=1)):
"""Tokens near bonding curve completion."""
tokens = asyncio.run(get_graduating_tokens(limit=limit))
_display_tokens(ctx, tokens)


@app.command("recommended")
def recommended(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n")):
@app.command("top", hidden=True)
def recommended(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n", min=1)):
"""Recommended tokens by pump.fun."""
tokens = asyncio.run(get_recommended_tokens(limit=limit))
_display_tokens(ctx, tokens)
Expand All @@ -91,7 +92,7 @@ def recommended(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n
def search(
ctx: typer.Context,
query: str = typer.Argument(...),
limit: int = typer.Option(20, "--limit", "-n"),
limit: int = typer.Option(20, "--limit", "-n", min=1),
):
"""Search tokens by keyword."""
tokens = asyncio.run(search_tokens(query, limit=limit))
Expand Down
23 changes: 23 additions & 0 deletions tests/test_commands/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import re

import pytest
from typer.testing import CliRunner

from pumpfun_cli.cli import app
Expand Down Expand Up @@ -170,3 +171,25 @@ def test_tokens_no_subcommand_shows_help():
"""Bare 'tokens' with no subcommand exits 0 and shows help."""
result = runner.invoke(app, ["tokens"])
assert result.exit_code == 0


@pytest.mark.parametrize("limit", ["0", "-1"])
@pytest.mark.parametrize(
("subcommand", "extra_args"),
[
("trending", []),
("new", []),
("graduating", []),
("top", []),
("recommended", []),
("search", ["dog"]),
],
)
def test_tokens_limit_must_be_at_least_one(limit, subcommand, extra_args):
"""Token listing commands reject zero and negative limits before execution."""
result = runner.invoke(app, ["tokens", subcommand, *extra_args, "--limit", limit])

assert result.exit_code == 2
output = _strip_ansi(result.output)
assert "Invalid value for" in output
assert "--limit" in output
Loading