Skip to content

Commit efc8d21

Browse files
designcodeclaude
andcommitted
fix: address PR review feedback for bundle command
- Extract readStdin to shared utility in src/utils/options.ts - Check for commas before existsSync to reduce key/file ambiguity - Document file-detection behavior in --keys description Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent df1510f commit efc8d21

4 files changed

Lines changed: 23 additions & 20 deletions

File tree

src/lib/bundle.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
import { getStorageConfig } from '@auth/provider.js';
22
import { bundle } from '@tigrisdata/storage';
33
import { exitWithError } from '@utils/exit.js';
4-
import { getFormat, getOption } from '@utils/options.js';
4+
import { getFormat, getOption, readStdin } from '@utils/options.js';
55
import { parseAnyPath } from '@utils/path.js';
66
import { createWriteStream, existsSync, readFileSync } from 'fs';
77
import { Readable } from 'stream';
88
import { pipeline } from 'stream/promises';
99

1010
const MAX_KEYS = 5000;
1111

12-
async function readStdin(): Promise<string> {
13-
const chunks: Buffer[] = [];
14-
for await (const chunk of process.stdin) {
15-
chunks.push(chunk);
16-
}
17-
return Buffer.concat(chunks).toString('utf-8');
18-
}
19-
2012
function parseKeys(content: string): string[] {
2113
return content
2214
.split('\n')
@@ -65,13 +57,18 @@ export default async function bundleCommand(options: Record<string, unknown>) {
6557
let keys: string[];
6658

6759
if (keysArg) {
68-
if (existsSync(keysArg)) {
69-
keys = parseKeys(readFileSync(keysArg, 'utf-8'));
70-
} else {
60+
if (keysArg.includes(',')) {
61+
// Commas present → always treat as inline comma-separated keys
7162
keys = keysArg
7263
.split(',')
7364
.map((k) => k.trim())
7465
.filter((k) => k.length > 0);
66+
} else if (existsSync(keysArg)) {
67+
// No commas and local file exists → read as keys file
68+
keys = parseKeys(readFileSync(keysArg, 'utf-8'));
69+
} else {
70+
// Single key
71+
keys = [keysArg.trim()];
7572
}
7673
} else if (!process.stdin.isTTY) {
7774
const input = await readStdin();

src/lib/iam/policies/utils.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import type { PolicyDocument } from '@tigrisdata/iam';
22

3-
export async function readStdin(): Promise<string> {
4-
const chunks: Buffer[] = [];
5-
for await (const chunk of process.stdin) {
6-
chunks.push(chunk);
7-
}
8-
return Buffer.concat(chunks).toString('utf-8');
9-
}
3+
export { readStdin } from '@utils/options.js';
104

115
export function parseDocument(jsonString: string): PolicyDocument {
126
const raw = JSON.parse(jsonString);

src/specs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ commands:
567567
- my-bucket
568568
- t3://my-bucket
569569
- name: keys
570-
description: "Comma-separated object keys, or path to a file with one key per line. If omitted, reads keys from stdin"
570+
description: "Comma-separated object keys, or path to a file with one key per line. If a local file matching the value exists, it is read as a keys file. If omitted, reads keys from stdin"
571571
alias: k
572572
- name: output
573573
description: Output file path. Defaults to stdout (for piping)

src/utils/options.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,15 @@ export function parseBoolean(
7373
if (typeof value === 'boolean') return value;
7474
return value === 'true';
7575
}
76+
77+
/**
78+
* Read all of stdin as a UTF-8 string.
79+
* Use when stdin is piped (i.e. `!process.stdin.isTTY`).
80+
*/
81+
export async function readStdin(): Promise<string> {
82+
const chunks: Buffer[] = [];
83+
for await (const chunk of process.stdin) {
84+
chunks.push(chunk);
85+
}
86+
return Buffer.concat(chunks).toString('utf-8');
87+
}

0 commit comments

Comments
 (0)