From 3e22c7b9ddff5b3230c1744f1a09294510d932dc Mon Sep 17 00:00:00 2001 From: "Dominik.Kotecki" Date: Sun, 13 Mar 2022 15:53:22 +0000 Subject: [PATCH] add pprint console notifier --- cmd/parse.go | 4 +++- go.mod | 4 ++++ go.sum | 6 ++++++ internal/console/pprint.go | 31 +++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 internal/console/pprint.go diff --git a/cmd/parse.go b/cmd/parse.go index def5238..5076204 100644 --- a/cmd/parse.go +++ b/cmd/parse.go @@ -4,6 +4,7 @@ import ( "context" "flag" + "github.com/dominikus1993/dev-news-bot/internal/console" "github.com/dominikus1993/dev-news-bot/internal/discord" "github.com/dominikus1993/dev-news-bot/internal/mongo" "github.com/dominikus1993/dev-news-bot/internal/parser/devto" @@ -57,7 +58,8 @@ func (p *ParseArticlesAndSendIt) Execute(ctx context.Context, f *flag.FlagSet, _ return subcommands.ExitFailure } defer discord.Close() - bradcaster := notifications.NewBroadcaster([]notifications.Notifier{discord}) + pprint := console.NewPPrintNotifier() + bradcaster := notifications.NewBroadcaster([]notifications.Notifier{pprint, discord}) usecase := usecase.NewParseArticlesAndSendItUseCase(articlesProvider, repo, bradcaster) err = usecase.Execute(ctx, p.quantity) diff --git a/go.mod b/go.mod index af4db22..154ea39 100644 --- a/go.mod +++ b/go.mod @@ -30,8 +30,12 @@ require ( github.com/google/go-cmp v0.5.7 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect + github.com/k0kubun/pp v3.0.1+incompatible // indirect + github.com/k0kubun/pp/v3 v3.1.0 // indirect github.com/kennygrant/sanitize v1.2.4 // indirect github.com/klauspost/compress v1.15.1 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect diff --git a/go.sum b/go.sum index 403323a..50365bb 100644 --- a/go.sum +++ b/go.sum @@ -298,6 +298,10 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40= +github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg= +github.com/k0kubun/pp/v3 v3.1.0 h1:ifxtqJkRZhw3h554/z/8zm6AAbyO4LLKDlA5eV+9O8Q= +github.com/k0kubun/pp/v3 v3.1.0/go.mod h1:vIrP5CF0n78pKHm2Ku6GVerpZBJvscg48WepUYEk2gw= github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o= github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -332,12 +336,14 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-slim v0.0.0-20200618151855-bde33eecb5ee/go.mod h1:ma9TUJeni8LGZMJvOwbAv/FOwiwqIMQN570LnpqCBSM= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= diff --git a/internal/console/pprint.go b/internal/console/pprint.go new file mode 100644 index 0000000..6f7ada5 --- /dev/null +++ b/internal/console/pprint.go @@ -0,0 +1,31 @@ +package console + +import ( + "context" + + "github.com/dominikus1993/dev-news-bot/pkg/model" + "github.com/k0kubun/pp" +) + +type PPrintNotifier struct { +} + +func NewPPrintNotifier() *PPrintNotifier { + return &PPrintNotifier{} +} + +func (not *PPrintNotifier) Notify(ctx context.Context, articles []model.Article) error { + scheme := pp.ColorScheme{ + Integer: pp.Green | pp.Bold, + Float: pp.Black | pp.BackgroundWhite | pp.Bold, + String: pp.Yellow, + } + + // Register it for usage + pp.SetColorScheme(scheme) + pp.Println("Parsed: ") + for _, article := range articles { + pp.Println(article) + } + return nil +}