@@ -133,28 +133,45 @@ export function parseArgs(argv) {
|
133 | 133 | skipBuild: false, |
134 | 134 | sourceDir: ROOT_DIR, |
135 | 135 | }; |
| 136 | +const seen = new Set(); |
| 137 | +const setOnce = (flag, key, value) => { |
| 138 | +if (seen.has(flag)) { |
| 139 | +throw new Error(`${flag} was provided more than once`); |
| 140 | +} |
| 141 | +seen.add(flag); |
| 142 | +options[key] = value; |
| 143 | +}; |
136 | 144 | for (let index = 0; index < argv.length; index += 1) { |
137 | 145 | const arg = argv[index]; |
138 | 146 | if (arg === "--output-dir") { |
139 | | -options.outputDir = readOptionValue(argv, index, arg); |
| 147 | +setOnce("--output-dir", "outputDir", readOptionValue(argv, index, arg)); |
140 | 148 | index += 1; |
141 | 149 | } else if (arg?.startsWith("--output-dir=")) { |
142 | | -options.outputDir = readEqualsOptionValue(arg.slice("--output-dir=".length), "--output-dir"); |
| 150 | +setOnce( |
| 151 | +"--output-dir", |
| 152 | +"outputDir", |
| 153 | +readEqualsOptionValue(arg.slice("--output-dir=".length), "--output-dir"), |
| 154 | +); |
143 | 155 | } else if (arg === "--output-name") { |
144 | | -options.outputName = readOptionValue(argv, index, arg); |
| 156 | +setOnce("--output-name", "outputName", readOptionValue(argv, index, arg)); |
145 | 157 | index += 1; |
146 | 158 | } else if (arg?.startsWith("--output-name=")) { |
147 | | -options.outputName = readEqualsOptionValue( |
148 | | -arg.slice("--output-name=".length), |
| 159 | +setOnce( |
149 | 160 | "--output-name", |
| 161 | +"outputName", |
| 162 | +readEqualsOptionValue(arg.slice("--output-name=".length), "--output-name"), |
150 | 163 | ); |
151 | 164 | } else if (arg === "--skip-build") { |
152 | | -options.skipBuild = true; |
| 165 | +setOnce(arg, "skipBuild", true); |
153 | 166 | } else if (arg === "--source-dir") { |
154 | | -options.sourceDir = readOptionValue(argv, index, arg); |
| 167 | +setOnce("--source-dir", "sourceDir", readOptionValue(argv, index, arg)); |
155 | 168 | index += 1; |
156 | 169 | } else if (arg?.startsWith("--source-dir=")) { |
157 | | -options.sourceDir = readEqualsOptionValue(arg.slice("--source-dir=".length), "--source-dir"); |
| 170 | +setOnce( |
| 171 | +"--source-dir", |
| 172 | +"sourceDir", |
| 173 | +readEqualsOptionValue(arg.slice("--source-dir=".length), "--source-dir"), |
| 174 | +); |
158 | 175 | } else { |
159 | 176 | throw new Error(`unknown argument: ${arg}`); |
160 | 177 | } |
|