feat!: print markdown to stdout by default, add --comment flag#9
Merged
Conversation
BREAKING CHANGE: `gh attach <N> FILE...` no longer posts a PR/issue
comment by default. The rendered markdown is written to stdout instead,
making the tool composable with shell pipelines, PR body edits, and
clipboards. Pass `--comment` for the pre-v0.3.0 upsert behavior.
Output contract after this change:
- stdout: always the bare rendered markdown (trimmed formatSection)
- stderr: progress line + one directly-embeddable URL per file
- with --comment: add a `Commented: <url>` line on stderr
Migration:
- Before (v0.2.x): gh attach 123 file.png (uploads + comments)
- After (v0.3.0): gh attach 123 file.png (uploads + prints md)
gh attach --comment 123 file.png (old behavior)
The architectural separation was already clean in the code —
GitDataClient and CommentClient have always been independent. This
commit makes the comment post opt-in instead of unconditional.
Smoke-tested end-to-end against #8: default
path prints markdown with no comment; --comment path posts the
comment and writes the same markdown to stdout.
There was a problem hiding this comment.
Code Review
This pull request changes the default behavior of gh attach to print rendered markdown to stdout instead of automatically posting a PR comment. A new --comment flag is introduced to opt-in to the previous behavior of upserting a comment. Additionally, raw URLs are now printed to stderr for better visibility when stdout is piped. The README has been updated with new usage examples and an explanation of the revised workflow. I have no feedback to provide.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 3 of the gh-attach roadmap: invert the default output behavior.
gh attach <N> FILE...no longer posts a PR/issue comment by default — it uploads the files and writes the rendered markdown to stdout, making the tool composable with shell pipelines, PR body edits, clipboards, and any other caller. The pre-v0.3.0 comment-posting behavior is still available via--comment.Why
The tool was always two independent things welded together: an upload step and a comment-posting step.
GitDataClientandCommentClienthave been separate since v0.1. Until now, the caller had no way to get the markdown out without also posting a comment — which meant embedding uploads in a PR body, a Slack message, an issue template, or anywhere else required either parsing theDone:URL back out or not using the tool at all.After this change, the caller owns the output.
gh attachproduces markdown; what you do with it is your call.Output contract
gh attach 123 file.pngUploading...+Uploaded:block with one URL per filegh attach --comment 123 file.pngUploading...+Uploaded:+Commented: <url>formatSectionoutput (trimmed, no<!-- gh-attach -->marker, no### Attachmentsheading). Callers add their own structure if they want.blob/<sha>/<file>?raw=trueURL per uploaded file, so interactive users see copy-pasteable links even when stdout is piped.--commentis additive, not modal: it adds a comment-post side-effect without changing what goes to stdout.gh attach --comment 123 file.png | tee backup.mdworks exactly as you'd expect.Migration
New use cases unlocked
Scope of changes
--commentflag, threads it throughrun(), replaces the unconditional comment post with: always emit markdown to stdout, always emit URL list to stderr, optional comment post guarded by the flag.~20 logical lines changed in main.go. The architectural separation was already in place — this PR just turns the comment step into an opt-in branch.
Verification
Smoke-tested end-to-end against a throwaway issue (
enthus-appdev/gh-attach#8, closed after test).Default path (no
--comment):Comments on
#8after this run: 0.With
--comment:Comments on
#8after this run: 1 (body starts with<!-- gh-attach -->\n### Attachments\n\n**With comment flag**\n...).go build ./...andgo vet ./...both clean.Test plan
--commentdiscoverable enough?v0.3.0as the right release tag for this breaking change