MCPcopy Index your code
hub / github.com/getsentry/XcodeBuildMCP / zodToYargsOption

Function zodToYargsOption

src/cli/schema-to-yargs.ts:172–240  ·  view source on GitHub ↗
(
  t: z.ZodType,
  opts: ZodToYargsOptionOptions = {},
)

Source from the content-addressed store, hash-verified

170 * Returns null for types that can't be represented as CLI flags.
171 */
172export function zodToYargsOption(
173 t: z.ZodType,
174 opts: ZodToYargsOptionOptions = {},
175): YargsOptionConfig | null {
176 const unwrapped = unwrap(t);
177 const description = getDescription(t);
178 const demandOption = !isOptional(t) && !opts.hasHydratedDefault;
179 const typeName = getZodTypeName(unwrapped);
180
181 if (typeName === 'string') {
182 return { type: 'string', describe: description, demandOption };
183 }
184
185 if (typeName === 'number' || typeName === 'int' || typeName === 'bigint') {
186 return { type: 'number', describe: description, demandOption };
187 }
188
189 if (typeName === 'boolean') {
190 return { type: 'boolean', describe: description, demandOption: false };
191 }
192
193 if (typeName === 'enum' || typeName === 'nativeEnum') {
194 const values = getEnumValues(unwrapped);
195 if (values) {
196 return {
197 type: 'string',
198 choices: values,
199 describe: description,
200 demandOption,
201 };
202 }
203 }
204
205 if (typeName === 'array') {
206 const element = getArrayElement(unwrapped);
207 if (element) {
208 const elemTypeName = getZodTypeName(unwrap(element));
209 if (elemTypeName === 'string') {
210 return { type: 'array', describe: description, demandOption: false };
211 }
212 if (elemTypeName === 'number') {
213 return {
214 type: 'array',
215 describe: description,
216 demandOption: false,
217 coerce: coerceNumberArray,
218 };
219 }
220 }
221 // Complex array types - use --json fallback
222 return null;
223 }
224
225 if (typeName === 'literal') {
226 const value = getLiteralValue(unwrapped);
227 if (typeof value === 'string') {
228 return { type: 'string', default: value, describe: description, demandOption: false };
229 }

Callers 2

schemaToYargsOptionsFunction · 0.85
getUnsupportedSchemaKeysFunction · 0.85

Calls 7

unwrapFunction · 0.85
getDescriptionFunction · 0.85
isOptionalFunction · 0.85
getZodTypeNameFunction · 0.85
getEnumValuesFunction · 0.85
getArrayElementFunction · 0.85
getLiteralValueFunction · 0.85

Tested by

no test coverage detected