|
1 | | -import rich_click as click |
| 1 | +import typer |
2 | 2 | from rich.traceback import install |
3 | 3 |
|
4 | | -# Removed reference to non-existent agent module |
| 4 | +# Import config command (still a Typer app) |
5 | 5 | from codegen.cli.commands.config.main import config_command |
6 | | -from codegen.cli.commands.init.main import init_command |
7 | | -from codegen.cli.commands.login.main import login_command |
8 | | -from codegen.cli.commands.logout.main import logout_command |
9 | | -from codegen.cli.commands.profile.main import profile_command |
10 | | -from codegen.cli.commands.style_debug.main import style_debug_command |
11 | | -from codegen.cli.commands.update.main import update_command |
| 6 | +from codegen import __version__ |
12 | 7 |
|
13 | 8 | install(show_locals=True) |
14 | 9 |
|
15 | 10 |
|
16 | | -@click.group(name="codegen") |
17 | | -@click.version_option(prog_name="codegen", message="%(version)s") |
18 | | -def main(): |
| 11 | +def version_callback(value: bool): |
| 12 | + """Print version and exit.""" |
| 13 | + if value: |
| 14 | + print(__version__) |
| 15 | + raise typer.Exit() |
| 16 | + |
| 17 | +# Create the main Typer app |
| 18 | +main = typer.Typer( |
| 19 | + name="codegen", |
| 20 | + help="Codegen CLI - Transform your code with AI.", |
| 21 | + rich_markup_mode="rich" |
| 22 | +) |
| 23 | + |
| 24 | +# Import the actual command functions |
| 25 | +from codegen.cli.commands.init.main import init |
| 26 | +from codegen.cli.commands.login.main import login |
| 27 | +from codegen.cli.commands.logout.main import logout |
| 28 | +from codegen.cli.commands.profile.main import profile |
| 29 | +from codegen.cli.commands.style_debug.main import style_debug |
| 30 | +from codegen.cli.commands.update.main import update |
| 31 | + |
| 32 | +# Add individual commands to the main app |
| 33 | +main.command("init", help="Initialize or update the Codegen folder.")(init) |
| 34 | +main.command("login", help="Store authentication token.")(login) |
| 35 | +main.command("logout", help="Clear stored authentication token.")(logout) |
| 36 | +main.command("profile", help="Display information about the currently authenticated user.")(profile) |
| 37 | +main.command("style-debug", help="Debug command to visualize CLI styling (spinners, etc).")(style_debug) |
| 38 | +main.command("update", help="Update Codegen to the latest or specified version")(update) |
| 39 | + |
| 40 | +# Config is a group, so add it as a typer |
| 41 | +main.add_typer(config_command, name="config") |
| 42 | + |
| 43 | + |
| 44 | +@main.callback() |
| 45 | +def main_callback( |
| 46 | + version: bool = typer.Option(False, "--version", callback=version_callback, is_eager=True, help="Show version and exit") |
| 47 | +): |
19 | 48 | """Codegen CLI - Transform your code with AI.""" |
20 | 49 | pass |
21 | 50 |
|
22 | 51 |
|
23 | | -# Add commands to the main group |
24 | | -main.add_command(init_command) |
25 | | -main.add_command(logout_command) |
26 | | -main.add_command(login_command) |
27 | | -main.add_command(profile_command) |
28 | | -main.add_command(style_debug_command) |
29 | | -main.add_command(update_command) |
30 | | -main.add_command(config_command) |
31 | | - |
32 | | - |
33 | 52 | if __name__ == "__main__": |
34 | 53 | main() |
0 commit comments