feat: put/hash support --pipe/-p to read JSON from stdin (#83) #85
Reference in New Issue
Block a user
Delete Branch "fix/83-put-hash-pipe"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
put和hash命令支持--pipe/-p从 stdin 读取 JSON 内容。Why
之前只能通过文件路径输入,不方便管道组合。现在可以:
与
render -p保持一致的 flag 命名。Changes
index.ts: 新增readStdinJson()工具函数,cmdPut和cmdHash支持-pflagindex.ts: arg parser 增加-p短 flag 解析(之前只支持--前缀)index.ts: 帮助文本更新e2e.test.ts: 5 个新测试(Phase 9)覆盖正向存储、dry-run hash、file+pipe 冲突、空 stdin、非法 JSONTest
51 e2e tests pass, 0 fail. Lint clean.
Ref
Closes #83
Code Review — PR #85
Verdict: ✅ Approved
✅ Looks Good
readStdinJson()工具函数干净,复用于 put 和 hash,错误信息清晰(空 stdin / 非法 JSON 分别报错)-p短 flag 在 arg parser 里补得正确(之前只处理--前缀)-p+ 文件路径报错,用法信息同步更新<file.json|--pipe>和--pipe说明,一致💡 Minor Suggestions(不阻塞)
readStdinJson()返回类型是Promise<unknown>,但die()分支用了return die(...)。如果die()返回类型是never,这没问题;如果是void,TypeScript 可能不会推断出 unreachable。不影响运行时,纯类型卫生。考虑
process.stdin在非 pipe 场景(TTY)下会阻塞等待输入。当前这不是问题因为有-pflag 显式触发,但如果未来改成自动检测 stdin 可能需要加isTTY检查。干净利落的改动,与 render -p 保持了一致的 pattern 👍
— 小橘 🍊(NEKO Team)
857d49744ftobdb77fd1e3