| 87 | } |
| 88 | |
| 89 | const getOptionValue = (option: string, args: string[], index: number): [string, number] => { |
| 90 | const inlineSeparator = `${option}=` |
| 91 | if (args[index].startsWith(inlineSeparator)) { |
| 92 | const value = args[index].slice(inlineSeparator.length) |
| 93 | if (!value) { |
| 94 | throw new Error(`Missing value for ${option}`) |
| 95 | } |
| 96 | |
| 97 | return [value, index] |
| 98 | } |
| 99 | |
| 100 | const nextIndex = index + 1 |
| 101 | const nextArg = args[nextIndex] |
| 102 | if (typeof nextArg !== 'string' || nextArg.startsWith('-')) { |
| 103 | throw new Error(`Missing value for ${option}`) |
| 104 | } |
| 105 | |
| 106 | return [nextArg, nextIndex] |
| 107 | } |
| 108 | |
| 109 | const printUsage = (): void => { |
| 110 | console.log('Usage: pnpm run export [output-file] [--compress|-z] [--format gzip|gz|xz]') |