export function buildCommand( commands: readonly string[], options: Partial | undefined, map: Partial>, ): string[] { const args = commands.slice(); if (options) { for (const [key, value] of Object.entries(options)) { if (value === undefined || value === null) { continue; } const option = map[key as keyof T]; // Empty string means positional argument, // they must be added at the end, // so let the caller handle it. if (option === undefined || option === "") { continue; } switch (typeof value) { case "boolean": if (value) { args.push(option); } break; case "number": args.push(option, value.toString()); break; case "string": args.push(option, value); break; default: throw new Error( `Unsupported type for option ${key}: ${typeof value}`, ); } } } return args; } export type SingleUser = number | "current"; export type SingleUserOrAll = SingleUser | "all"; export type Optional = { [K in keyof T]?: T[K] | undefined };