55from typing import Annotated
66
77import typer
8+ from rich import print
89
910from cppython .console .schema import ConsoleConfiguration , ConsoleInterface
1011from cppython .core .schema import ProjectConfiguration
1112from cppython .project import Project
1213
13- app = typer .Typer ()
14+ app = typer .Typer (no_args_is_help = True )
15+
16+
17+ def get_enabled_project (context : typer .Context ) -> Project :
18+ """Helper to load and validate an enabled Project from CLI context."""
19+ configuration = context .find_object (ConsoleConfiguration )
20+ if configuration is None :
21+ raise ValueError ('The configuration object is missing' )
22+
23+ path = configuration .project_configuration .project_root / 'pyproject.toml'
24+ pyproject_data = loads (path .read_text (encoding = 'utf-8' ))
25+
26+ project = Project (configuration .project_configuration , configuration .interface , pyproject_data )
27+ if not project .enabled :
28+ print ('[bold red]Error[/bold red]: Project is not enabled. Please check your pyproject.toml configuration.' )
29+ raise typer .Exit (code = 1 )
30+ return project
1431
1532
1633def _find_pyproject_file () -> Path :
@@ -75,13 +92,7 @@ def install(
7592 Raises:
7693 ValueError: If the configuration object is missing
7794 """
78- if (configuration := context .find_object (ConsoleConfiguration )) is None :
79- raise ValueError ('The configuration object is missing' )
80-
81- path = configuration .project_configuration .project_root / 'pyproject.toml'
82- pyproject_data = loads (path .read_text (encoding = 'utf-8' ))
83-
84- project = Project (configuration .project_configuration , configuration .interface , pyproject_data )
95+ project = get_enabled_project (context )
8596 project .install ()
8697
8798
@@ -97,13 +108,7 @@ def update(
97108 Raises:
98109 ValueError: If the configuration object is missing
99110 """
100- if (configuration := context .find_object (ConsoleConfiguration )) is None :
101- raise ValueError ('The configuration object is missing' )
102-
103- path = configuration .project_configuration .project_root / 'pyproject.toml'
104- pyproject_data = loads (path .read_text (encoding = 'utf-8' ))
105-
106- project = Project (configuration .project_configuration , configuration .interface , pyproject_data )
111+ project = get_enabled_project (context )
107112 project .update ()
108113
109114
@@ -112,3 +117,19 @@ def list_command(
112117 _ : typer .Context ,
113118) -> None :
114119 """Prints project information"""
120+
121+
122+ @app .command ()
123+ def publish (
124+ context : typer .Context ,
125+ ) -> None :
126+ """Publish API call
127+
128+ Args:
129+ context: The CLI configuration object
130+
131+ Raises:
132+ ValueError: If the configuration object is missing
133+ """
134+ project = get_enabled_project (context )
135+ project .publish ()
0 commit comments