Skip to content

Refactor shell-hook installation to idempotent ensure semantics (raise on unsupported shell) #144

Description

@d3mlabs-ai-flow

From review feedback on #140 (https://github.com/d3mlabs/dev/blob/HEAD/lib/dev/cd/hook_installer.rb):

HookInstaller#ensure_installed currently returns Symbol | false (:added, :already_present, or false for an unsupported shell), which makes for a weak type and models the method's name poorly.

Ensuring the hook is installed is idempotent — a caller of an idempotent ensure has no business knowing whether the work was already done. The contract should be:

  • Success = not raising. Drop :already_present; the ensure either leaves the hook installed or raises.
  • Unsupported shell raises a typed error (e.g. UnsupportedShellError), caught at a higher level where the user-facing hint is printed.

Scope:

Note: some callers currently print different hints for "just added" vs "present but not active in this shell" — the refactor needs to either fold those messages into one, or surface that distinction some other way that doesn't leak the tri-state into the return type.

Requested by @JPDuchesne in #140 (comment) (thread on hook_installer.rb).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions