From bbdfb302052737f09f0847dbeaaf4c9e67fd1d25 Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 1 Aug 2022 15:33:41 +0200 Subject: [PATCH] feat: add null:// update handler --- README.md | 4 +++ internal/command/common.go | 2 ++ internal/data/updater/null/updater_handler.go | 34 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 internal/data/updater/null/updater_handler.go diff --git a/README.md b/README.md index e0a6cdf..45282db 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,10 @@ echo '{}' | FORMIDABLE_BROWSER="firefox" frmd \ > TODO: Write doc + example +#### `null://` + +> TODO: Write doc + example + #### `file://` > TODO: Write doc + example diff --git a/internal/command/common.go b/internal/command/common.go index feb4bbb..22d8479 100644 --- a/internal/command/common.go +++ b/internal/command/common.go @@ -16,6 +16,7 @@ import ( "forge.cadoles.com/wpetit/formidable/internal/data/scheme/stdin" "forge.cadoles.com/wpetit/formidable/internal/data/updater/exec" fileUpdater "forge.cadoles.com/wpetit/formidable/internal/data/updater/file" + "forge.cadoles.com/wpetit/formidable/internal/data/updater/null" "forge.cadoles.com/wpetit/formidable/internal/data/updater/stdout" "forge.cadoles.com/wpetit/formidable/internal/def" "github.com/pkg/errors" @@ -205,6 +206,7 @@ func newUpdater() *data.Updater { stdout.NewUpdaterHandler(), fileUpdater.NewUpdaterHandler(), exec.NewUpdaterHandler(), + null.NewUpdaterHandler(), ) } diff --git a/internal/data/updater/null/updater_handler.go b/internal/data/updater/null/updater_handler.go new file mode 100644 index 0000000..61fd66a --- /dev/null +++ b/internal/data/updater/null/updater_handler.go @@ -0,0 +1,34 @@ +package null + +import ( + "io" + "net/url" +) + +const SchemeNull = "null" + +type UpdaterHandler struct{} + +func (h *UpdaterHandler) Match(url *url.URL) bool { + return url.Scheme == SchemeNull +} + +func (u *UpdaterHandler) Update(url *url.URL) (io.WriteCloser, error) { + return &nullCloser{}, nil +} + +func NewUpdaterHandler() *UpdaterHandler { + return &UpdaterHandler{} +} + +type nullCloser struct { + io.WriteCloser +} + +func (c *nullCloser) Write(p []byte) (n int, err error) { + return io.Discard.Write(p) +} + +func (c *nullCloser) Close() error { + return nil +}