This commit is contained in:
parent
bfc763c0c0
commit
5b763dc7b4
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -60,13 +61,15 @@ func flags() []cli.Flag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func action(context context.Context, c *cli.Command) error {
|
func action(context context.Context, c *cli.Command) error {
|
||||||
|
logger.Log("Notify starting")
|
||||||
sourcePath := c.String(constants.Source)
|
sourcePath := c.String(constants.Source)
|
||||||
var input io.Reader
|
var input io.Reader
|
||||||
|
|
||||||
if sourcePath == "" {
|
if sourcePath == "" {
|
||||||
fmt.Println("Reading from standard input (stdin)...")
|
logger.Log("Reading from standard input (stdin)...")
|
||||||
input = os.Stdin
|
input = bufio.NewReader(os.Stdin)
|
||||||
} else {
|
} else {
|
||||||
|
logger.Log("Reading from file (stdin)...")
|
||||||
file, err := common.ReadFile(sourcePath)
|
file, err := common.ReadFile(sourcePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -133,13 +136,14 @@ func action(context context.Context, c *cli.Command) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readInput(input io.Reader) (common.ActiveResponse, error) {
|
func readInput(input io.Reader) (common.ActiveResponse, error) {
|
||||||
|
logger.Log("Parsing input")
|
||||||
var ar common.ActiveResponse
|
var ar common.ActiveResponse
|
||||||
|
|
||||||
decoder := json.NewDecoder(input)
|
decoder := json.NewDecoder(input)
|
||||||
|
|
||||||
err := decoder.Decode(&ar)
|
err := decoder.Decode(&ar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error decoding JSON from stdin: %v\n", err)
|
logger.Log(fmt.Sprintf("Error decoding JSON from stdin: %v\n", err))
|
||||||
return ar, err
|
return ar, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user