| 27 | } |
| 28 | |
| 29 | function parseArgs(args) { |
| 30 | const options = { |
| 31 | network: true, |
| 32 | mounts: {}, |
| 33 | debug: false, |
| 34 | }; |
| 35 | |
| 36 | for (let i = 0; i < args.length; i++) { |
| 37 | const arg = args[i]; |
| 38 | |
| 39 | switch (arg) { |
| 40 | case '--help': |
| 41 | case '-h': |
| 42 | printUsage(); |
| 43 | process.exit(0); |
| 44 | break; |
| 45 | |
| 46 | case '--network': |
| 47 | case '-n': |
| 48 | options.network = true; |
| 49 | break; |
| 50 | |
| 51 | case '--no-network': |
| 52 | options.network = false; |
| 53 | break; |
| 54 | |
| 55 | case '--mount': |
| 56 | case '-m': |
| 57 | const mountArg = args[++i]; |
| 58 | if (!mountArg) { |
| 59 | console.error('Error: --mount requires a path argument'); |
| 60 | process.exit(1); |
| 61 | } |
| 62 | |
| 63 | // Support both "/host/path" and "/host/path:/vm/path" formats |
| 64 | if (mountArg.includes(':') && !mountArg.startsWith('/') || mountArg.split(':').length > 2) { |
| 65 | // Handle Windows-style paths or explicit VM path |
| 66 | const lastColon = mountArg.lastIndexOf(':'); |
| 67 | if (lastColon > 0 && mountArg[lastColon - 1] !== '\\') { |
| 68 | const hostPath = mountArg.substring(0, lastColon); |
| 69 | const vmPath = mountArg.substring(lastColon + 1); |
| 70 | options.mounts[vmPath] = path.resolve(hostPath); |
| 71 | } else { |
| 72 | options.mounts['/mnt/host'] = path.resolve(mountArg); |
| 73 | } |
| 74 | } else if (mountArg.includes(':')) { |
| 75 | const [hostPath, vmPath] = mountArg.split(':'); |
| 76 | options.mounts[vmPath] = path.resolve(hostPath); |
| 77 | } else { |
| 78 | options.mounts['/mnt/host'] = path.resolve(mountArg); |
| 79 | } |
| 80 | break; |
| 81 | |
| 82 | case '--debug': |
| 83 | case '-d': |
| 84 | options.debug = true; |
| 85 | break; |
| 86 | |