Skip to content

Commit a5ef61f

Browse files
committed
fix stdin
1 parent 5f03e0f commit a5ef61f

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
run: bun install --frozen-lockfile
4646

4747
- name: Run unit tests
48-
run: bun test tests/config.test.ts tests/output.test.ts tests/client.test.ts tests/errors.test.ts
48+
run: bun test
4949

5050
- name: Run integration tests
5151
run: bun test --timeout 60000 tests/integration/

src/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ import {
2727
unknownOptionError,
2828
} from './errors.js';
2929
import { VERSION } from './version.js';
30+
import * as fs from 'node:fs';
31+
32+
/**
33+
* Check if stdin has data available (for detecting piped input in non-TTY environments)
34+
* Uses fstatSync to check if stdin is a FIFO/pipe with data
35+
*/
36+
function hasStdinData(): boolean {
37+
try {
38+
const stats = fs.fstatSync(0); // fd 0 is stdin
39+
// Check if it's a FIFO (pipe) or regular file with size
40+
return stats.isFIFO() || (stats.isFile() && stats.size > 0);
41+
} catch {
42+
return false;
43+
}
44+
}
3045

3146
interface ParsedArgs {
3247
command: 'list' | 'grep' | 'info' | 'call' | 'help' | 'version';
@@ -104,7 +119,7 @@ function parseArgs(args: string[]): ParsedArgs {
104119
if (positional.length > 1) {
105120
result.command = 'call';
106121
result.args = positional.slice(1).join(' ');
107-
} else if (!process.stdin.isTTY) {
122+
} else if (!process.stdin.isTTY && hasStdinData()) {
108123
// If stdin has data (piped input), treat as call command
109124
result.command = 'call';
110125
} else {

0 commit comments

Comments
 (0)