Skip to content

Commit 1fe6d2a

Browse files
Fix CLI command structure to avoid double nesting
- Remove Typer app wrappers from individual command files - Convert commands to standalone functions with Typer decorators - Update main CLI to import and register individual functions - Fixes the double nesting issue (e.g., codegen init init) - All commands now work correctly: init, login, logout, profile, style-debug, update - Config command remains as Typer app since it has subcommands
1 parent 1317833 commit 1fe6d2a

File tree

7 files changed

+7
-37
lines changed

7 files changed

+7
-37
lines changed

src/codegen/cli/cli.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import typer
22
from rich.traceback import install
33

4-
# Removed reference to non-existent agent module
4+
# Import config command (still a Typer app)
55
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
126

137
install(show_locals=True)
148

@@ -28,12 +22,12 @@
2822
from codegen.cli.commands.update.main import update
2923

3024
# Add individual commands to the main app
31-
main.command("init")(init)
32-
main.command("login")(login)
33-
main.command("logout")(logout)
34-
main.command("profile")(profile)
35-
main.command("style-debug")(style_debug)
36-
main.command("update")(update)
25+
main.command("init", help="Initialize or update the Codegen folder.")(init)
26+
main.command("login", help="Store authentication token.")(login)
27+
main.command("logout", help="Clear stored authentication token.")(logout)
28+
main.command("profile", help="Display information about the currently authenticated user.")(profile)
29+
main.command("style-debug", help="Debug command to visualize CLI styling (spinners, etc).")(style_debug)
30+
main.command("update", help="Update Codegen to the latest or specified version")(update)
3731

3832
# Config is a group, so add it as a typer
3933
main.add_typer(config_command, name="config")

src/codegen/cli/commands/init/main.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
from codegen.cli.rich.codeblocks import format_command
1010
from codegen.shared.path import get_git_root_path
1111

12-
# Create a Typer app for the init command
13-
init_command = typer.Typer(help="Initialize or update the Codegen folder.")
14-
15-
@init_command.command()
1612
def init(
1713
path: Optional[str] = typer.Option(None, help="Path within a git repository. Defaults to the current directory."),
1814
token: Optional[str] = typer.Option(None, help="Access token for the git repository. Required for full functionality."),

src/codegen/cli/commands/login/main.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
from codegen.cli.auth.login import login_routine
66
from codegen.cli.auth.token_manager import get_current_token
77

8-
# Create a Typer app for the login command
9-
login_command = typer.Typer(help="Store authentication token.")
10-
11-
@login_command.command()
128
def login(token: Optional[str] = typer.Option(None, help="API token for authentication")):
139
"""Store authentication token."""
1410
# Check if already authenticated

src/codegen/cli/commands/logout/main.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33

44
from codegen.cli.auth.token_manager import TokenManager
55

6-
# Create a Typer app for the logout command
7-
logout_command = typer.Typer(help="Clear stored authentication token.")
8-
9-
@logout_command.command()
106
def logout():
117
"""Clear stored authentication token."""
128
token_manager = TokenManager()

src/codegen/cli/commands/profile/main.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ def requires_init(func):
1313
"""Simple stub decorator that does nothing."""
1414
return func
1515

16-
# Create a Typer app for the profile command
17-
profile_command = typer.Typer(help="Display information about the currently authenticated user.")
18-
19-
@profile_command.command()
2016
@requires_auth
2117
@requires_init
2218
def profile(session: CodegenSession):

src/codegen/cli/commands/style_debug/main.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
from codegen.cli.rich.spinners import create_spinner
88

9-
# Create a Typer app for the style-debug command
10-
style_debug_command = typer.Typer(help="Debug command to visualize CLI styling (spinners, etc).")
11-
12-
@style_debug_command.command()
139
def style_debug(text: str = typer.Option("Loading...", help="Text to show in the spinner")):
1410
"""Debug command to visualize CLI styling (spinners, etc)."""
1511
try:

src/codegen/cli/commands/update/main.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ def install_package(package: str, *args: str) -> None:
3131
subprocess.check_call([sys.executable, "-m", "pip", "install", package, *args])
3232

3333

34-
# Create a Typer app for the update command
35-
update_command = typer.Typer(help="Update Codegen to the latest or specified version")
36-
37-
@update_command.command()
3834
def update(
3935
list_: bool = typer.Option(False, "--list", "-l", help="List all supported versions of the codegen"),
4036
version: Optional[str] = typer.Option(None, "--version", "-v", help="Update to a specific version of the codegen")

0 commit comments

Comments
 (0)