1313app = typer .Typer (no_args_is_help = True )
1414
1515
16+ def get_enabled_project (context : typer .Context ) -> Project :
17+ """Helper to load and validate an enabled Project from CLI context."""
18+ configuration = context .find_object (ConsoleConfiguration )
19+ if configuration is None :
20+ raise ValueError ('The configuration object is missing' )
21+
22+ path = configuration .project_configuration .project_root / 'pyproject.toml'
23+ pyproject_data = loads (path .read_text (encoding = 'utf-8' ))
24+
25+ project = Project (configuration .project_configuration , configuration .interface , pyproject_data )
26+ if not project .enabled :
27+ typer .secho (
28+ 'Error: Project is not enabled. Please check your pyproject.toml configuration.' ,
29+ fg = typer .colors .RED ,
30+ bold = True ,
31+ )
32+ raise typer .Exit (code = 1 )
33+ return project
34+
35+
1636def _find_pyproject_file () -> Path :
1737 """Searches upward for a pyproject.toml file
1838
@@ -75,13 +95,7 @@ def install(
7595 Raises:
7696 ValueError: If the configuration object is missing
7797 """
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 )
98+ project = get_enabled_project (context )
8599 project .install ()
86100
87101
@@ -97,13 +111,7 @@ def update(
97111 Raises:
98112 ValueError: If the configuration object is missing
99113 """
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 )
114+ project = get_enabled_project (context )
107115 project .update ()
108116
109117
@@ -126,11 +134,5 @@ def publish(
126134 Raises:
127135 ValueError: If the configuration object is missing
128136 """
129- if (configuration := context .find_object (ConsoleConfiguration )) is None :
130- raise ValueError ('The configuration object is missing' )
131-
132- path = configuration .project_configuration .project_root / 'pyproject.toml'
133- pyproject_data = loads (path .read_text (encoding = 'utf-8' ))
134-
135- project = Project (configuration .project_configuration , configuration .interface , pyproject_data )
137+ project = get_enabled_project (context )
136138 project .publish ()
0 commit comments