Skip to content

Commit

Permalink
🔥 Simplify hook package
Browse files Browse the repository at this point in the history
The hook package had unnecessary complexity when choosing which action
to apply.

Testing was also difficult as instantiating the hook package also
required providing the options.

Tests were removed as this is now a trivial function.
  • Loading branch information
mikelorant committed Feb 17, 2023
1 parent 048ab26 commit 2db4c08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 119 deletions.
25 changes: 5 additions & 20 deletions internal/hook/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

type Hook struct {
Action Action
Creator Creator
Locater Locater
Deleter Deleter
Expand Down Expand Up @@ -64,9 +63,8 @@ const (
Marker = "Code generated by Committed. DO NOT EDIT."
)

func New(opts Options) Hook {
func New() Hook {
return Hook{
Action: action(opts),
Creator: os.OpenFile,
Deleter: os.Remove,
Opener: os.Open,
Expand All @@ -76,26 +74,13 @@ func New(opts Options) Hook {
}
}

func (h *Hook) Do() error {
switch h.Action {
case ActionInstall:
return nil
case ActionUninstall:
return nil
}

return ErrAction
}

func action(opts Options) Action {
func (h *Hook) Do(opts Options) error {
switch {
case opts.Install:
return ActionInstall
return h.Install()
case opts.Uninstall:
return ActionUninstall
case opts.Commit:
return ActionCommit
return h.Uninstall()
}

return ActionUnset
return ErrAction
}
99 changes: 0 additions & 99 deletions internal/hook/hook_test.go

This file was deleted.

0 comments on commit 2db4c08

Please sign in to comment.