(argv)
| 45 | } |
| 46 | |
| 47 | function parseArgs(argv) { |
| 48 | const options = { |
| 49 | write: false, |
| 50 | envFile: path.join(ROOT_DIR, ".env"), |
| 51 | domains: null, |
| 52 | prefix: null, |
| 53 | concurrency: 4, |
| 54 | limit: null, |
| 55 | verbose: false, |
| 56 | targets: [], |
| 57 | }; |
| 58 | |
| 59 | for (let i = 0; i < argv.length; i += 1) { |
| 60 | const arg = argv[i]; |
| 61 | if (arg === "--help" || arg === "-h") { |
| 62 | options.help = true; |
| 63 | } else if (arg === "--write") { |
| 64 | options.write = true; |
| 65 | } else if (arg === "--verbose") { |
| 66 | options.verbose = true; |
| 67 | } else if (arg === "--env") { |
| 68 | options.envFile = path.resolve(ROOT_DIR, requireValue(argv, i)); |
| 69 | i += 1; |
| 70 | } else if (arg.startsWith("--env=")) { |
| 71 | options.envFile = path.resolve(ROOT_DIR, arg.slice("--env=".length)); |
| 72 | } else if (arg === "--domains") { |
| 73 | options.domains = parseList(requireValue(argv, i)); |
| 74 | i += 1; |
| 75 | } else if (arg.startsWith("--domains=")) { |
| 76 | options.domains = parseList(arg.slice("--domains=".length)); |
| 77 | } else if (arg === "--prefix") { |
| 78 | options.prefix = requireValue(argv, i); |
| 79 | i += 1; |
| 80 | } else if (arg.startsWith("--prefix=")) { |
| 81 | options.prefix = arg.slice("--prefix=".length); |
| 82 | } else if (arg === "--concurrency") { |
| 83 | options.concurrency = parsePositiveInt(requireValue(argv, i), "--concurrency"); |
| 84 | i += 1; |
| 85 | } else if (arg.startsWith("--concurrency=")) { |
| 86 | options.concurrency = parsePositiveInt(arg.slice("--concurrency=".length), "--concurrency"); |
| 87 | } else if (arg === "--limit") { |
| 88 | options.limit = parsePositiveInt(requireValue(argv, i), "--limit"); |
| 89 | i += 1; |
| 90 | } else if (arg.startsWith("--limit=")) { |
| 91 | options.limit = parsePositiveInt(arg.slice("--limit=".length), "--limit"); |
| 92 | } else if (arg.startsWith("-")) { |
| 93 | throw new Error(`Unknown option: ${arg}`); |
| 94 | } else { |
| 95 | options.targets.push(path.resolve(ROOT_DIR, arg)); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | if (options.targets.length === 0) { |
| 100 | options.targets.push(DEFAULT_TARGET); |
| 101 | } |
| 102 | |
| 103 | return options; |
| 104 | } |
no test coverage detected