diff options
author | Koni Marti <koni.marti@gmail.com> | 2023-11-24 16:03:01 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-12-30 15:42:09 +0100 |
commit | f98382d1dfc8970d3006fcc2175dd514bf7e07d0 (patch) | |
tree | 506a085a962d6d83ac223a2ad43e98a27afcc0f9 /lib/pama/pama.go | |
parent | 07c1cefcf62dbd094b6f97061c469264ee089898 (diff) | |
download | aerc-f98382d1dfc8970d3006fcc2175dd514bf7e07d0.tar.gz |
patch/init: add init sub-cmd
Implement the :patch init command to initialize a new project.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/pama/pama.go')
-rw-r--r-- | lib/pama/pama.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/pama/pama.go b/lib/pama/pama.go new file mode 100644 index 00000000..6fe91fee --- /dev/null +++ b/lib/pama/pama.go @@ -0,0 +1,51 @@ +package pama + +import ( + "fmt" + + "git.sr.ht/~rjarry/aerc/lib/pama/models" + "git.sr.ht/~rjarry/aerc/lib/pama/revctrl" + "git.sr.ht/~rjarry/aerc/lib/pama/store" +) + +type ( + detectFn func(string) (string, string, error) + rcFn func(string, string) (models.RevisionController, error) + storeFn func() models.PersistentStorer +) + +type PatchManager struct { + detect detectFn + rc rcFn + store storeFn +} + +func New() PatchManager { + return PatchManager{ + detect: revctrl.Detect, + rc: revctrl.New, + store: store.Store, + } +} + +func FromFunc(d detectFn, r rcFn, s storeFn) PatchManager { + return PatchManager{ + detect: d, + rc: r, + store: s, + } +} + +func storeErr(err error) error { + if err == nil { + return nil + } + return fmt.Errorf("store error: %w", err) +} + +func revErr(err error) error { + if err == nil { + return nil + } + return fmt.Errorf("revision control error: %w", err) +} |