-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (36 loc) · 716 Bytes
/
Copy pathmain.go
File metadata and controls
41 lines (36 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"github.com/thatmattlove/oui/v2/cmd"
)
func isPiped() bool {
fileInfo, _ := os.Stdin.Stat()
return fileInfo.Mode()&os.ModeCharDevice == 0
}
var splitPattern = regexp.MustCompile(`[\n\r\t\s]`)
func main() {
args := os.Args
if isPiped() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
parts := splitPattern.Split(line, -1)
for _, part := range parts {
clean := splitPattern.ReplaceAllString(part, "")
args = append(args, clean)
}
}
}
if len(args) == 1 {
args = append(args, "--help")
}
err := cmd.New(Version).Run(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(0)
}