Skip to content

Commit

Permalink
notifier/stdout: Stdout notifier maximbaz#31
Browse files Browse the repository at this point in the history
Make it easier to use in scripts by having a stdout notifier that can
be ingested via. a pipe.
  • Loading branch information
lentinj committed May 15, 2022
1 parent 72dc33d commit 2208817
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ func main() {

envVerbose := truthyValues[strings.ToLower(os.Getenv("YUBIKEY_TOUCH_DETECTOR_VERBOSE"))]
envLibnotify := truthyValues[strings.ToLower(os.Getenv("YUBIKEY_TOUCH_DETECTOR_LIBNOTIFY"))]
envStdout := truthyValues[strings.ToLower(os.Getenv("YUBIKEY_TOUCH_DETECTOR_STDOUT"))]

var version bool
var verbose bool
var libnotify bool
var stdout bool
var gpgPubringPath string

flag.BoolVar(&version, "version", false, "print version and exit")
flag.BoolVar(&verbose, "v", envVerbose, "print verbose output")
flag.BoolVar(&libnotify, "libnotify", envLibnotify, "show desktop notifications using libnotify")
flag.BoolVar(&stdout, "stdout", envStdout, "Output notifications to stdout")
flag.Parse()

if version {
Expand Down Expand Up @@ -63,6 +66,9 @@ func main() {
if libnotify {
go notifier.SetupLibnotifyNotifier(notifiers)
}
if stdout {
go notifier.SetupStdoutNotifier(notifiers)
}

requestGPGCheck := make(chan bool)
go detector.CheckGPGOnRequest(requestGPGCheck, notifiers)
Expand Down
18 changes: 18 additions & 0 deletions notifier/stdout.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package notifier

import (
"os"
"sync"
)

// SetupStdoutNotifier configures a notifier to log to stdout
func SetupStdoutNotifier(notifiers *sync.Map) {
touch := make(chan Message, 10)
notifiers.Store("notifier/stdout", touch)

for {
value := <-touch
os.Stdout.WriteString(string(value))
os.Stdout.WriteString("\n")
}
}

0 comments on commit 2208817

Please sign in to comment.