Skip to content

Commit

Permalink
feat(event): show info from pipe input
Browse files Browse the repository at this point in the history
  • Loading branch information
crispgm committed Aug 5, 2024
1 parent 68208eb commit 8d5a563
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cmd/kicker-cli/cmd/event_info.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package cmd

import (
"bufio"
"fmt"
"os"
"sort"
"strings"

"github.com/pterm/pterm"
"github.com/spf13/cobra"
Expand All @@ -24,10 +27,22 @@ var eventInfoCmd = &cobra.Command{
Short: "Show event details",
Long: "Show event details",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
errorMessageAndExit("Please present an event ID")
var arg string
if isInputFromPipe() {
scanner := bufio.NewScanner(bufio.NewReader(bufio.NewReader(os.Stdin)))
for scanner.Scan() {
arg = strings.Trim(scanner.Text(), " \t\n")
break
}
if len(arg) == 0 {
errorMessageAndExit("Please present an event ID")
}
} else {
if len(args) == 0 {
errorMessageAndExit("Please present an event ID")
}
arg = args[0]
}
arg := args[0]
instance := initInstanceAndLoadConf()
e := instance.GetEvent(arg)
if e == nil {
Expand Down
5 changes: 5 additions & 0 deletions cmd/kicker-cli/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ func dashIfEmpty(s string) string {
}
return s
}

func isInputFromPipe() bool {
fileInfo, _ := os.Stdin.Stat()
return fileInfo.Mode()&os.ModeCharDevice == 0
}

0 comments on commit 8d5a563

Please sign in to comment.