feat(cli): add argument parser and TTY detection
- New CLI argument parser supporting subcommands, short/long flags, flag values, positional args, aliases, and --help per command - TTY detection via fstatSync (Bun compat: process.stdin.isTTY is undefined in Bun 1.3.x) - Extended types: CommitResult, StreamCallbacks
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
// TTY detection for Bun compatibility.
|
||||
// Bun does not set process.stdin.isTTY, so we use fs.fstatSync.
|
||||
|
||||
import { fstatSync } from "node:fs";
|
||||
|
||||
let _stdinTTY: boolean | null = null;
|
||||
|
||||
export function initTTY(): void {
|
||||
if (_stdinTTY !== null) return;
|
||||
|
||||
try {
|
||||
// fd 0 = stdin. On Unix, a TTY is a character device.
|
||||
const stat = fstatSync(0);
|
||||
_stdinTTY = stat.isCharacterDevice();
|
||||
} catch {
|
||||
_stdinTTY = false;
|
||||
}
|
||||
}
|
||||
|
||||
export function isStdinTTY(): boolean {
|
||||
if (_stdinTTY === null) initTTY();
|
||||
return _stdinTTY!;
|
||||
}
|
||||
|
||||
export function isStdoutTTY(): boolean {
|
||||
// Use a heuristic for stdout — check if we're in a terminal
|
||||
if (process.env.TERM || process.env.TERM_PROGRAM) return true;
|
||||
if (process.env.NO_COLOR) return false;
|
||||
// Try fstat on fd 1 (stdout)
|
||||
try {
|
||||
const stat = fstatSync(1);
|
||||
return stat.isCharacterDevice();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user