agentscope-ai / agentscope-ai/QwenPaw

[Feature]: Support colored cmd and more using `typer` instead of `click`

Offen
#4,472 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
TypeScript
Sterne
35k
Forks
3.1k
Ø Merge
1 T. 13 Std.
Gemergte PRs (30 T.)
228

Beschreibung

## Summary

Currently cmds/CLIs in QwenPaw are built upon `click`. While `click` is a good choice compared with using python built-in argument parsing libraries, it does not support natively latest features in python like type annotation and coloring.

By switching to `typer`, the definitions of cmds would be more elegant and comes with coloring without extra effort. It is also very friendly to type linters.

## Component(s) Affected

- [ ] Core / Backend (app, agents, config, providers, utils, local_models)
- [ ] Console (frontend web UI)
- [ ] Channels (DingTalk, Feishu, QQ, Discord, iMessage, etc.)
- [ ] Skills
- [x] CLI
- [ ] Documentation (website)
- [ ] Tests
- [ ] CI/CD
- [ ] Scripts / Deploy

## Problem / Motivation

1. Definition of cmds/CLIs are currently not reduntant in defining types of command line arguments due to the fact `click` does not support type annotation.
2. Cmds/CLIs do not support coloring

## Proposed Solution

Use `typer` to redefine all cmds/CLIs.

An example would be

original:
```python
@click.command("desktop")
@click.option(
"--host",
default="127.0.0.1",
show_default=True,
help="Bind host for the app server.",
)
@click.option(
"--log-level",
default="info",
type=click.Choice(
["critical", "error", "warning", "info", "debug", "trace"],
case_sensitive=False,
),
show_default=True,
help="Log level for the app process.",
)
def desktop_cmd(
host: str,
log_level: str,
) -> None:
...
```

with typer:
```python
class LogLevel(str, Enum):
critical = "critical"
error = "error"
warning = "warning"
info = "info"
debug = "debug"
trace = "trace"

app = typer.Typer()

@app.command("desktop")
def desktop_cmd(
host: Annotated[
str,
typer.Option(help="Bind host for the app server."),
] = "127.0.0.1",
log_level: Annotated[
LogLevel,
typer.Option(help="Log level for the app process."),
] = LogLevel.info,
) -> None:
```

## Alternatives Considered

None

## Additional Context

nothing

## Willing to Contribute

- [x] I am willing to open a PR for this feature (after discussion).

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.