Skip to content

cli: rework +ssh-cache internals and user interface#12814

Merged
mitchellh merged 1 commit into
ghostty-org:mainfrom
jparise:ssh-cache
May 27, 2026
Merged

cli: rework +ssh-cache internals and user interface#12814
mitchellh merged 1 commit into
ghostty-org:mainfrom
jparise:ssh-cache

Conversation

@jparise
Copy link
Copy Markdown
Contributor

@jparise jparise commented May 25, 2026

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.


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.

@ghostty-bot ghostty-bot Bot added the cli `ghostty` command-line interface label May 25, 2026
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.
@tristan957
Copy link
Copy Markdown
Member

Do we have have any precedent for subcommands? I generally prefer ghostty +ssh add xyz whereas you have gone with long options. Obviously being consistent is better than anything, but figured I would bring it up.

@jparise
Copy link
Copy Markdown
Contributor Author

jparise commented May 26, 2026

Do we have have any precedent for subcommands? I generally prefer ghostty +ssh add xyz whereas you have gone with long options. Obviously being consistent is better than anything, but figured I would bring it up.

This maintains the +ssh-cache interface that's already shipped, which used options rather than subcommands. I think it would be fine to further revise this to use commands (with compatibility for the previous flags), but that might be for a follow-up change given all of the things this already does.

I don't think I'd try to merge this functionality into +ssh, because that's positioned as a ssh wrapper, and it's command line parsing already has a high bar to avoid ambiguities between the Ghostty-specific flags and SSH's.

@tristan957
Copy link
Copy Markdown
Member

Do we have have any precedent for subcommands? I generally prefer ghostty +ssh add xyz whereas you have gone with long options. Obviously being consistent is better than anything, but figured I would bring it up.

This maintains the +ssh-cache interface that's already shipped, which used options rather than subcommands. I think it would be fine to further revise this to use commands (with compatibility for the previous flags), but that might be for a follow-up change given all of the things this already does.

I don't think I'd try to merge this functionality into +ssh, because that's positioned as a ssh wrapper, and it's command line parsing already has a high bar to avoid ambiguities between the Ghostty-specific flags and SSH's.

Makes sense. Thanks!

@mitchellh mitchellh added this to the 1.4.0 milestone May 27, 2026
@mitchellh mitchellh merged commit 756fda7 into ghostty-org:main May 27, 2026
177 of 182 checks passed
@jparise jparise deleted the ssh-cache branch May 27, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli `ghostty` command-line interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants