|
5 | 5 | import sys |
6 | 6 | import argparse |
7 | 7 | from .core import omnipkg, ConfigManager |
| 8 | +from pathlib import Path |
8 | 9 |
|
9 | 10 | def print_header(title): |
10 | 11 | """Prints a consistent, pretty header for CLI sections.""" |
@@ -36,7 +37,14 @@ def create_parser(): |
36 | 37 | subparsers = parser.add_subparsers(dest='command', help='All available commands:', required=True) |
37 | 38 |
|
38 | 39 | install_parser = subparsers.add_parser('install', help='Install packages (with downgrade protection)') |
39 | | - install_parser.add_argument('packages', nargs='+', help='Packages to install (e.g., "requests==2.25.1")') |
| 40 | + # Make 'packages' optional (nargs='*') to allow using -r instead |
| 41 | + install_parser.add_argument('packages', nargs='*', help='Packages to install (e.g., "requests==2.25.1")') |
| 42 | + # Add the new -r/--requirement flag |
| 43 | + install_parser.add_argument( |
| 44 | + '-r', '--requirement', |
| 45 | + help='Install from the given requirements file.', |
| 46 | + metavar='FILE' |
| 47 | + ) |
40 | 48 |
|
41 | 49 | uninstall_parser = subparsers.add_parser('uninstall', help='Uninstall packages from main env or bubbles') |
42 | 50 | uninstall_parser.add_argument('packages', nargs='+', help='Packages to uninstall (e.g., "requests" or "requests==2.25.1")') |
@@ -95,8 +103,43 @@ def main(): |
95 | 103 | # Now, create the main instance, PASSING IN the loaded config |
96 | 104 | pkg_instance = omnipkg(cm.config) |
97 | 105 | try: |
| 106 | + # In omnipkg/cli.py -> main() |
| 107 | + |
98 | 108 | if args.command == 'install': |
99 | | - return pkg_instance.smart_install(args.packages) |
| 109 | + packages_to_process = [] |
| 110 | + |
| 111 | + if args.requirement: |
| 112 | + # User provided a requirements file |
| 113 | + req_path = Path(args.requirement) |
| 114 | + if not req_path.is_file(): |
| 115 | + print(f"❌ Error: Requirements file not found at '{req_path}'") |
| 116 | + return 1 |
| 117 | + |
| 118 | + print(f"📄 Reading packages from {req_path.name}...") |
| 119 | + # In omnipkg/cli.py -> main() |
| 120 | + |
| 121 | + with open(req_path, 'r') as f: |
| 122 | + # Parse the file, handling inline comments and empty lines |
| 123 | + packages_to_process = [] |
| 124 | + for line in f: |
| 125 | + # Get the part before any comment and strip whitespace |
| 126 | + clean_line = line.split('#')[0].strip() |
| 127 | + # Only add it to our list if it's not an empty string |
| 128 | + if clean_line: |
| 129 | + packages_to_process.append(clean_line) |
| 130 | + |
| 131 | + elif args.packages: |
| 132 | + # User provided packages directly on the command line |
| 133 | + packages_to_process = args.packages |
| 134 | + |
| 135 | + else: |
| 136 | + # No packages or file provided |
| 137 | + print("❌ Error: You must either specify packages to install or use the -r flag.") |
| 138 | + print(" Example: `omnipkg install requests` or `omnipkg install -r requirements.txt`") |
| 139 | + return 1 |
| 140 | + |
| 141 | + # The magic happens here: pass the list to your existing core logic |
| 142 | + return pkg_instance.smart_install(packages_to_process) |
100 | 143 | elif args.command == 'uninstall': |
101 | 144 | return pkg_instance.smart_uninstall(args.packages, force=args.yes) |
102 | 145 |
|
|
0 commit comments