INNER CODE UNIT · TypeScript
changeDirectoryOrExit
superagent-ai/grok-cli · src/index.ts:158
function changeDirectoryOrExit(directory: string | undefined) {
if (!directory) {
return;
}
try {
process.chdir(directory);
} catch (err: unknown) {
const msg = err instanceof Error ? err.message : String(err);
console.error(`Cannot change to directory ${directory}: ${msg}`);
process.exit(1);
}
}
type CliOptions = Record<string, string | boolean | undefined>;
function stringOption(value: string | boolean | undefined): string | undefined {
return typeof value === "string" ? value : undefined;