(argv)
| 41 | } |
| 42 | |
| 43 | function parseArgs(argv) { |
| 44 | const args = { _: [] }; |
| 45 | for (let index = 0; index < argv.length; index += 1) { |
| 46 | const arg = argv[index]; |
| 47 | if (!arg.startsWith("--")) { |
| 48 | args._.push(arg); |
| 49 | continue; |
| 50 | } |
| 51 | const key = arg.slice(2); |
| 52 | if (!VALID_OPTIONS.has(key)) { |
| 53 | fail(`Unknown option: --${key}.`); |
| 54 | } |
| 55 | const value = argv[index + 1]; |
| 56 | if (OPTIONS_WITH_VALUES.has(key)) { |
| 57 | if (value == null) { |
| 58 | fail(`Missing value for --${key}.`); |
| 59 | } |
| 60 | if (value.startsWith("--") && !OPTIONS_ALLOWING_DASH_VALUES.has(key)) { |
| 61 | fail(`Missing value for --${key}.`); |
| 62 | } |
| 63 | args[key] = value; |
| 64 | index += 1; |
| 65 | continue; |
| 66 | } |
| 67 | } |
| 68 | return args; |
| 69 | } |
| 70 | |
| 71 | function printJson(value) { |
| 72 | process.stdout.write(`${JSON.stringify(value, null, 2)}\n`); |
no test coverage detected