File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 3131from mcpm .migration import V1ConfigDetector , V1ToV2Migrator
3232from mcpm .utils .logging_config import setup_logging
3333from mcpm .utils .rich_click_config import click , get_header_text
34+ import os
35+ from pathlib import Path
3436
3537console = Console () # stdout for regular CLI output
3638err_console = Console (stderr = True ) # stderr for errors/tracebacks
@@ -86,6 +88,21 @@ def wrapper(*args, **kwargs):
8688@handle_exceptions
8789def main (ctx , version , help_flag ):
8890 """Main entry point for MCPM CLI."""
91+
92+ try :
93+ # Check if the current working directory is valid.
94+ os .getcwd ()
95+ except OSError :
96+ # If getcwd() fails, it means the directory doesn't exist.
97+ # This can happen when mcpm is called from certain environments
98+ # like some Electron apps that don't set a valid cwd.
99+ home_dir = str (Path .home ())
100+ err_console .print (
101+ f"Current working directory is invalid. Changing to home directory: { home_dir } " ,
102+ style = "bold yellow"
103+ )
104+ os .chdir (home_dir )
105+
89106 if version :
90107 print_logo ()
91108 return
You can’t perform that action at this time.
0 commit comments