agentscope-ai / agentscope-ai/QwenPaw

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

Ouverte
#4,472 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
enhancement
Langage dominant
Python
Étoiles
34.9k
Forks
3.1k
Merge moyen
1 j 15 h
PR mergées (30 j)
225

Description

## 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).

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.