Add -S/--session-or-attach and 'session attach --create' flags#116
Open
yochum wants to merge 7 commits into
Open
Add -S/--session-or-attach and 'session attach --create' flags#116yochum wants to merge 7 commits into
yochum wants to merge 7 commits into
Conversation
Adds a ResolveMode enum and a shared helper that validates a session name, checks whether the session exists on disk, and populates either attach_session or new_session_name on ParseResult based on mode. No callers yet; existing -s and 'session attach' paths will be migrated in follow-up commits.
Replaces the inline validation/existence/SessionAlreadyExists logic in the -s/--session branch of parseArgs with a single call to resolveSessionTarget(.create_only). Error messages are preserved byte-for-byte. Also widens the errdefer to cover attach_session now that the helper may populate either field.
Replaces the inline sessionExists check in the 'session attach <name>' branch with resolveSessionTarget(.attach_only). Adds name validation to attach (malformed names now error with the validation message instead of the less helpful 'Session not found'). The no-name path continues to use findMostRecentSession unchanged.
New top-level flag that attaches to an existing session with the given name or creates a new one if missing. Routes through resolveSessionTarget with .attach_or_create. Extends the -s/session conflict check to cover -S, and forwards new_session_name from session subcommand results so P2.2 (--create) can populate it.
When present on 'session attach', routes through resolveSessionTarget with .attach_or_create so the named session is attached if it exists and created otherwise. Accepted before or after the name argument. Without a name, errors with a dedicated MissingArgument message (distinct from the no-arg 'attach' which falls back to findMostRecentSession).
Adds -S/--session-or-attach to the top-level options list and mentions --create/-c on the 'session attach' usage line. Column widths adjusted so everything lines up.
Adds 7 test cases covering the full matrix:
- create_only x {missing, existing}
- attach_only x {existing, missing}
- attach_or_create x {existing, missing}
- invalid name (empty, too long, contains space, contains slash)
Splits sessionExists into sessionExistsInDir(dir, name) plus a public
wrapper that resolves the real sessions dir from HOME, and introduces
a test-only sessions_dir_override so tests can point the resolver at
std.testing.tmpDir() without touching the user's state dir.
Author
|
Note: rename / delete skip session name validation. I can follow up with a PR to tighten those up. |
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
-S, --session-or-attach <name>— attach to an existing session, create one if missing.--create/-ctoprise session attach— same behavior via the subcommand surface.resolveSessionTargethelper;-s,session attach, and both new flags all funnel through it (eliminates two parallel implementations of validate + existence-check).session attachto validate session names. Malformed names now error with the existing validation message instead of "Session not found" — small behavior change, strictly more informative.prise --helpandprise session --helpto document the new flags.resolveSessionTargetcovering the full mode × existence matrix plus validation failures (first tests inmain.zig).Motivation
Today
prise session attach <name>errors if missing andprise -s <name>errors if existing — so users have to shell-wrap the two to get a "attach or create" command.-Sand--createclose that gap.Test plan
zig buildsucceedszig build test— 246/246 passing (baseline 239 + 7 new)-s <new>/-s <existing>/-s <invalid>session attach <existing>/<missing>/<invalid>/ no-arg falls back to most recent-S <existing>/-S <missing>/-S <invalid>/-Swith no argsession attach --create <existing>/<missing>/-calias-S foo session attach barerrorsNotes
sessions_dir_overrideglobal so tests can pointsessionExistsatstd.testing.tmpDir()instead of the real~/.local/state/prise/sessions.rename/deletestill skip name validation (latent gap, out of scope).