Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/mcpm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from mcpm.migration import V1ConfigDetector, V1ToV2Migrator
from mcpm.utils.logging_config import setup_logging
from mcpm.utils.rich_click_config import click, get_header_text
import os
from pathlib import Path

console = Console() # stdout for regular CLI output
err_console = Console(stderr=True) # stderr for errors/tracebacks
Expand Down Expand Up @@ -86,6 +88,21 @@ def wrapper(*args, **kwargs):
@handle_exceptions
def main(ctx, version, help_flag):
"""Main entry point for MCPM CLI."""

try:
# Check if the current working directory is valid.
os.getcwd()
except OSError:
# If getcwd() fails, it means the directory doesn't exist.
# This can happen when mcpm is called from certain environments
# like some Electron apps that don't set a valid cwd.
home_dir = str(Path.home())
err_console.print(
f"Current working directory is invalid. Changing to home directory: {home_dir}",
style="bold yellow"
)
os.chdir(home_dir)

if version:
print_logo()
return
Expand Down