feat(cli): support reading spec from stdin via --file -#555
Conversation
Allows passing "-" as the --file argument to read specs from stdin on generate, lint, and complete-word subcommands. This enables piping specs from other tools (e.g., `jbang usage | usage generate markdown --file -`). Not supported for exec/shell subcommands which pass stdin through to the child process. Closes #546 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #555 +/- ##
==========================================
- Coverage 72.40% 70.27% -2.14%
==========================================
Files 48 48
Lines 6830 7067 +237
Branches 6830 7067 +237
==========================================
+ Hits 4945 4966 +21
- Misses 1242 1325 +83
- Partials 643 776 +133 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Greptile SummaryThis PR adds Key changes:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant CLI
participant generate/mod.rs
participant stdin
participant Spec
User->>CLI: usage generate <cmd> --file -
CLI->>generate/mod.rs: file_or_spec(Some("-"), ...) OR parse_file_or_stdin("-")
generate/mod.rs->>generate/mod.rs: file.as_os_str() == "-" ?
generate/mod.rs->>stdin: read_to_string()
stdin-->>generate/mod.rs: raw spec string
generate/mod.rs->>Spec: input.parse()
Spec-->>generate/mod.rs: Spec { ... }
generate/mod.rs-->>CLI: Ok(Spec)
CLI-->>User: generated output
User->>CLI: usage generate <cmd> --file path/to/spec.kdl
CLI->>generate/mod.rs: parse_file_or_stdin("path/to/spec.kdl")
generate/mod.rs->>Spec: Spec::parse_file(path)
Spec-->>generate/mod.rs: Spec { ... }
generate/mod.rs-->>CLI: Ok(Spec)
CLI-->>User: generated output
|
There was a problem hiding this comment.
Code Review
This pull request adds support for reading specs from stdin via --file -. This is achieved by adding a new helper function parse_file_or_stdin which is then used across various generate subcommands and the lint command. The changes also include updates to documentation, CLI help texts, and generated artifacts to reflect the new functionality. My review includes one suggestion to reduce code duplication by reusing the newly introduced helper function.
| if file.as_os_str() == "-" { | ||
| read_spec_from_stdin() | ||
| } else { | ||
| Spec::parse_file(file) | ||
| } |
When --file - is used, show "stdin" in generated file headers and completion script comments instead of the raw "-" sentinel value. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
### 🚀 Features - **(cli)** render all doc-related fields in --help output by [@jdx](https://github.com/jdx) in [#554](#554) - **(cli)** support reading spec from stdin via --file - by [@jdx](https://github.com/jdx) in [#555](#555) ### 🐛 Bug Fixes - **(zsh)** remove trailing space from completions and add directory slash by [@jdx](https://github.com/jdx) in [#556](#556) - use field assignment for non-exhaustive Spec in benchmarks by [@jdx](https://github.com/jdx) in [#552](#552) ### 📦️ Dependency Updates - update apple-actions/import-codesign-certs digest to fe74d46 by [@renovate[bot]](https://github.com/renovate[bot]) in [#550](#550) - update codecov/codecov-action digest to 1af5884 by [@renovate[bot]](https://github.com/renovate[bot]) in [#551](#551) - lock file maintenance by [@renovate[bot]](https://github.com/renovate[bot]) in [#547](#547)
Summary
--file -to read specs from stdin on all generate subcommands, lint, and complete-wordjbang usage | usage generate markdown --file -)--filehelp text to document stdin supportCloses #546
Test plan
echo 'name "test" flag "-v --verbose" help="verbose"' | usage generate json --file -produces valid JSON output--file /path/to/filestill works as beforeusage generate markdown --file - --out-file out.mdworks with piped input🤖 Generated with Claude Code
Note
Low Risk
Low-risk CLI enhancement that only affects how usage specs are read when
--fileis set to-; primary risk is unintended behavior changes for edge-case file paths or stdin handling.Overview
Adds support for piping a usage spec via stdin by treating
--file -as “read spec from stdin” acrosscomplete-word,generate completion/manpage/markdown, andlint(via new shared helpers incli/src/cli/generate/mod.rs).Updates generated metadata/docs (
usage.usage.kdl, manpage, reference JSON/markdown, Fig spec) to document the stdin behavior, and adjusts generated output labeling to usestdininstead of-where a source filename is surfaced (e.g., completionsource_fileand Fig@generatedheader).Written by Cursor Bugbot for commit 98d3919. This will update automatically on new commits. Configure here.