Project Files
src / git / parameter-schemas.ts
import { z } from "zod"
/**
* Builds a zod string schema for a value that will be forwarded to git as a positional argument.
* The schema enforces a 1-character minimum, the supplied maximum length, and rejects values that
* begin with `-` so the value cannot be reinterpreted as a git flag.
*
* @param fieldName Human-readable parameter name embedded in the validation error message.
* @param maxLength Maximum allowed string length.
* @returns A configured zod schema suitable for further chaining (`.optional`, `.default`, `.refine`, `.describe`).
*/
export function gitSafeString(fieldName: string, maxLength: number) {
return z
.string()
.min(1)
.max(maxLength)
.refine(value => !value.startsWith("-"), {
message: `${fieldName} must not start with '-' (would be parsed as a git flag).`,
})
}