cli: rework +ssh-cache internals and user interface#12814
Conversation
This change primarily focused on a revised +ssh-cache user interface,
but it also reworks a bunch of the internals.
The primary CLI improvement is support for positional arguments and a
consistent list output format that includes both the ISO-formatted
timestamp and relative age.
ghostty +ssh-cache # List all cached destinations
ghostty +ssh-cache user@example.com # Show that destination
ghostty +ssh-cache example.com # Show all users on that host
ghostty +ssh-cache --add=user@example.com # Manually add a destination
ghostty +ssh-cache --remove=user@example.com # Remove a destination
ghostty +ssh-cache --prune=30d # Remove entries older than 30 days
ghostty +ssh-cache --clear # Clear entire cache
Notable, we now support a --prune operation that replaces the previous
--expire-days flag that was never actually hooked up to anything (!!).
--prune also supports a wider range of Duration-based values.
We're also much more consistent with error codes: 0=success, 1=failure,
2=usage.
While working on those changes, I also reworked the cache internals,
particularly the code around timestamp handling and errors. For example,
I dropped the explicit error sets because they were growing unwieldy,
and in practice we only matched on a subset of those errors.
Lastly, overall test coverage should be much improved, especially around
the time- and allocation-related operations.
|
Do we have have any precedent for subcommands? I generally prefer |
This maintains the I don't think I'd try to merge this functionality into |
Makes sense. Thanks! |
This change primarily focused on a revised +ssh-cache user interface, but it also reworks a bunch of the internals.
The primary CLI improvement is support for positional arguments and a consistent list output format that includes both the ISO-formatted timestamp and relative age.
Notable, we now support a --prune operation that replaces the previous --expire-days flag that was never actually hooked up to anything (!!). --prune also supports a wider range of Duration-based values.
We're also much more consistent with error codes: 0=success, 1=failure, 2=usage.
While working on those changes, I also reworked the cache internals, particularly the code around timestamp handling and errors. For example, I dropped the explicit error sets because they were growing unwieldy, and in practice we only matched on a subset of those errors.
Lastly, overall test coverage should be much improved, especially around the time- and allocation-related operations.
AI Disclosure: I made a lot of iterative, AI-assisted (Claude Opus 4.7) correctness passes over this work. It was particularly helpful in tracing through the various failure modes, and it wrote those unit tests in the process.