-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat(help): add common flags section and cache-age hints (#785) #859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5fe6860
feat(help): add common flags section and cache-age hints (#785)
BYK cfae461
fix(response-cache): remove duplicate section header
BYK 88991c7
fix: address review findings — --help interception, bare-return suppr…
BYK ca89bb5
revert(cli): drop --help interception — agents need the terse output
BYK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /** | ||
| * Cache-age hint for command output. | ||
| * | ||
| * Reads the process-global cache-hit state from `response-cache.ts` and | ||
| * formats a human-readable hint like "cached · 3m ago · use -f to refresh". | ||
| * Applied automatically by `buildCommand` in `command.ts` — individual | ||
| * commands don't need to call this themselves. | ||
| * | ||
| * getsentry/cli#785 item #1 — `-f/--fresh` flag discoverability. | ||
| * | ||
| * @module | ||
| */ | ||
|
|
||
| import { getLastCacheHitAge } from "./response-cache.js"; | ||
|
|
||
| /** | ||
| * Format a millisecond duration as a compact human-readable string. | ||
| * | ||
| * - `< 5s` → `"just now"` | ||
| * - `5s–59s` → `"Ns ago"` | ||
| * - `1m–59m` → `"Nm ago"` | ||
| * - `1h–23h` → `"Nh ago"` | ||
| * - `≥ 24h` → `"Nd ago"` | ||
| * | ||
| * @internal Exported for testing | ||
| */ | ||
| export function formatAge(ms: number): string { | ||
| const seconds = Math.floor(ms / 1000); | ||
| if (seconds < 5) { | ||
| return "just now"; | ||
| } | ||
| if (seconds < 60) { | ||
| return `${seconds}s ago`; | ||
| } | ||
| const minutes = Math.floor(seconds / 60); | ||
| if (minutes < 60) { | ||
| return `${minutes}m ago`; | ||
| } | ||
| const hours = Math.floor(minutes / 60); | ||
| if (hours < 24) { | ||
| return `${hours}h ago`; | ||
| } | ||
| const days = Math.floor(hours / 24); | ||
| return `${days}d ago`; | ||
| } | ||
|
|
||
| /** | ||
| * Build a cache-age hint string, or `undefined` when the last request was | ||
| * not served from cache. | ||
| * | ||
| * When multiple API calls run in parallel (e.g. `Promise.all`), the | ||
| * displayed age corresponds to whichever resolves last — acceptable | ||
| * since all hits share similar ages in practice. | ||
| * | ||
| * Example output: `"cached · 3m ago · use -f to refresh"` | ||
| */ | ||
| export function formatCacheHint(): string | undefined { | ||
| const ageMs = getLastCacheHitAge(); | ||
| if (ageMs === undefined) { | ||
| return; | ||
| } | ||
| return `cached · ${formatAge(ageMs)} · use -f to refresh`; | ||
| } | ||
|
|
||
| /** | ||
| * Append a cache-age hint to an existing hint string. | ||
| * | ||
| * - Both present → `"existingHint | cached · 3m ago · ..."` | ||
| * - Only cache hint → `"cached · 3m ago · ..."` | ||
| * - Only existing → `"existingHint"` (unchanged) | ||
| * - Neither → `undefined` | ||
| */ | ||
| export function appendCacheHint( | ||
| existingHint: string | undefined | ||
| ): string | undefined { | ||
| const cacheHint = formatCacheHint(); | ||
| if (existingHint && cacheHint) { | ||
| return `${existingHint} | ${cacheHint}`; | ||
| } | ||
| return cacheHint ?? existingHint; | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.