Class SessionStore

java.lang.Object
com.shaft.commandline.session.SessionStore

public final class SessionStore extends Object
Persists the current SessionInfo as JSON at <baseDir>/cli-session.json.
  • Constructor Details

    • SessionStore

      public SessionStore()
      Creates a store rooted at <user.home>/.shaft.
    • SessionStore

      public SessionStore(Path baseDir)
      Creates a store rooted at the given directory, for tests.
      Parameters:
      baseDir - the directory the session file lives in
  • Method Details

    • path

      public Path path()
      Returns:
      the path to the session file, whether or not it currently exists
    • load

      public Optional<SessionInfo> load()
      Loads the persisted session, tolerating a missing or corrupt file.
      Returns:
      the persisted session, or empty if none is stored or it cannot be parsed
    • save

      public void save(SessionInfo info)
      Persists the session, writing atomically via a temp file plus move-replace.
      Parameters:
      info - the session to persist
    • clear

      public void clear()
      Deletes the session file if present.