-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
64 lines (52 loc) · 1.56 KB
/
main.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"flag"
"fmt"
"github.com/fatih/color"
"github.com/deepjyoti30/yaf/util"
)
// Declare vars
var (
separator string
keyPrefix string
noColor bool
excludeFields string
version bool
)
func init() {
flag.StringVar(&separator, "separator", " ", "Separator to be used between the key and the value")
flag.StringVar(&keyPrefix, "key-prefix", "▪ ", "Prefix to be set before the key is printed")
flag.BoolVar(&noColor, "no-color", false, "Disable showing colors in the output")
flag.StringVar(&excludeFields, "exclude", "username hostname", "Exclude the passed fields from output. Values should be space separated, eg: `disk os`")
flag.BoolVar(&version, "version", false, "Print current version of yaf installed")
}
func main() {
// Parse flags
flag.Parse()
// Disable the color if flag is passed
if noColor {
color.NoColor = true
}
// If to show version or not
if version {
// Print the version and exit.
fmt.Printf("yaf %s\n", util.ArgsDefaultValues().Version)
return
}
var details = map[string]util.GetterFunc{
"username": util.GetUser,
"hostname": util.GetHostname,
"os": util.GetDistroName,
"kernel": util.GetKernelVersion,
"shell": util.GetShell,
"uptime": util.GetUptime,
"memory": util.GetMemory,
"disk": util.GetDiskUsage,
}
// Parse the fields to exclude string
fieldsToExclude := util.ParseExcludeFields(excludeFields)
rightContent := util.GenerateContent(details, separator, keyPrefix, fieldsToExclude)
for _, value := range rightContent {
fmt.Println(value)
}
}