(path, multiple)
| 260 | * @returns {number} number of arguments added |
| 261 | */ |
| 262 | const addFlag = (path, multiple) => { |
| 263 | const argConfigBase = schemaToArgumentConfig(path[0].schema); |
| 264 | if (!argConfigBase) return 0; |
| 265 | |
| 266 | const negatedDescription = getNegatedDescription(path); |
| 267 | const name = pathToArgumentName(path[0].path); |
| 268 | /** @type {ArgumentConfig} */ |
| 269 | const argConfig = { |
| 270 | ...argConfigBase, |
| 271 | multiple, |
| 272 | description: getDescription(path), |
| 273 | path: path[0].path |
| 274 | }; |
| 275 | |
| 276 | if (negatedDescription) { |
| 277 | argConfig.negatedDescription = negatedDescription; |
| 278 | } |
| 279 | |
| 280 | if (!flags[name]) { |
| 281 | flags[name] = { |
| 282 | configs: [], |
| 283 | description: undefined, |
| 284 | simpleType: |
| 285 | /** @type {SimpleType} */ |
| 286 | (/** @type {unknown} */ (undefined)), |
| 287 | multiple: /** @type {boolean} */ (/** @type {unknown} */ (undefined)) |
| 288 | }; |
| 289 | } |
| 290 | |
| 291 | if ( |
| 292 | flags[name].configs.some( |
| 293 | (item) => JSON.stringify(item) === JSON.stringify(argConfig) |
| 294 | ) |
| 295 | ) { |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | if ( |
| 300 | flags[name].configs.some( |
| 301 | (item) => item.type === argConfig.type && item.multiple !== multiple |
| 302 | ) |
| 303 | ) { |
| 304 | if (multiple) { |
| 305 | throw new Error( |
| 306 | `Conflicting schema for ${path[0].path} (${getOriginPath( |
| 307 | path |
| 308 | )}) with ${ |
| 309 | argConfig.type |
| 310 | } type (array type must be before single item type)` |
| 311 | ); |
| 312 | } |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | flags[name].configs.push(argConfig); |
| 317 | |
| 318 | return 1; |
| 319 | }; |
no test coverage detected