()
| 62 | } |
| 63 | |
| 64 | function buildOptionSpecs(): OptionSpec[] { |
| 65 | const definitionsByKey = new Map<FlagKey, FlagDefinition[]>(); |
| 66 | for (const definition of getFlagDefinitions()) { |
| 67 | const existing = definitionsByKey.get(definition.key); |
| 68 | if (existing) existing.push(definition); |
| 69 | else definitionsByKey.set(definition.key, [definition]); |
| 70 | } |
| 71 | |
| 72 | const supportedCommandsByKey = new Map<FlagKey, Set<string>>(); |
| 73 | for (const key of GLOBAL_FLAG_KEYS) { |
| 74 | supportedCommandsByKey.set(key, new Set(['*'])); |
| 75 | } |
| 76 | for (const command of listCliCommandNames()) { |
| 77 | const schema = getCliCommandSchema(command); |
| 78 | for (const key of [...(schema.allowedFlags ?? []), ...(schema.supportedFlags ?? [])]) { |
| 79 | const existing = supportedCommandsByKey.get(key); |
| 80 | if (existing && existing.has('*')) continue; |
| 81 | if (existing) existing.add(command); |
| 82 | else supportedCommandsByKey.set(key, new Set([command])); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | return [...definitionsByKey.entries()] |
| 87 | .map(([key, flagDefinitions]) => ({ |
| 88 | key, |
| 89 | flagDefinitions, |
| 90 | config: { |
| 91 | enabled: !CONFIG_EXCLUDED_FLAG_KEYS.has(key), |
| 92 | key, |
| 93 | }, |
| 94 | env: { |
| 95 | names: ENV_EXCLUDED_FLAG_KEYS.has(key) ? [] : [buildPrimaryEnvVarName(key)], |
| 96 | }, |
| 97 | supportsCommand(command: string | null): boolean { |
| 98 | const supported = supportedCommandsByKey.get(key); |
| 99 | if (!supported) return false; |
| 100 | if (supported.has('*')) return true; |
| 101 | if (!command) return false; |
| 102 | return supported.has(command); |
| 103 | }, |
| 104 | })) |
| 105 | .sort((left, right) => left.key.localeCompare(right.key)); |
| 106 | } |
| 107 | |
| 108 | function primaryFlagDefinition(spec: OptionSpec): FlagDefinition { |
| 109 | const definition = spec.flagDefinitions[0]; |
no test coverage detected