refactor: flatten CLI directory structure - remove 'box in a box'
BEFORE: /opt/aitbc/cli/ ├── aitbc_cli/ # Python package (box in a box) │ ├── commands/ │ ├── main.py │ └── ... ├── setup.py AFTER: /opt/aitbc/cli/ # Flat structure ├── commands/ # Direct access ├── main.py # Direct access ├── auth/ ├── config/ ├── core/ ├── models/ ├── utils/ ├── plugins.py └── setup.py CHANGES MADE: - Moved all files from aitbc_cli/ to cli/ root - Fixed all relative imports (from . to absolute imports) - Updated setup.py entry point: aitbc_cli.main → main - Added CLI directory to Python path in entry script - Simplified deployment.py to remove dependency on deleted core.deployment - Fixed import paths in all command files - Recreated virtual environment with new structure BENEFITS: - Eliminated 'box in a box' nesting - Simpler directory structure - Direct access to all modules - Cleaner imports - Easier maintenance and development - CLI works with both 'python main.py' and 'aitbc' commands
This commit is contained in:
31
cli/utils/subprocess.py
Normal file
31
cli/utils/subprocess.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import List, Optional, Union, Any
|
||||
from . import error, output
|
||||
|
||||
def run_subprocess(cmd: List[str], check: bool = True, capture_output: bool = True, shell: bool = False, **kwargs: Any) -> Optional[Union[str, subprocess.CompletedProcess]]:
|
||||
"""Run a subprocess command safely with logging"""
|
||||
try:
|
||||
if shell:
|
||||
# When shell=True, cmd should be a string
|
||||
cmd_str = " ".join(cmd) if isinstance(cmd, list) else cmd
|
||||
result = subprocess.run(cmd_str, shell=True, check=check, capture_output=capture_output, text=True, **kwargs)
|
||||
else:
|
||||
result = subprocess.run(cmd, check=check, capture_output=capture_output, text=True, **kwargs)
|
||||
|
||||
if capture_output:
|
||||
return result.stdout.strip()
|
||||
return result
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
error(f"Command failed with exit code {e.returncode}")
|
||||
if capture_output and getattr(e, 'stderr', None):
|
||||
print(e.stderr, file=sys.stderr)
|
||||
if check:
|
||||
sys.exit(e.returncode)
|
||||
return getattr(e, 'stdout', None) if capture_output else None
|
||||
except Exception as e:
|
||||
error(f"Failed to execute command: {e}")
|
||||
if check:
|
||||
sys.exit(1)
|
||||
return None
|
||||
Reference in New Issue
Block a user