package main import ( "fmt" "os" "strconv" "github.com/wahyd4/redhat" ) const defaultTopLines = 10 func main() { args := os.Args if len(args) < 2 || len(args) > 3 { panic(`Usage: go run main.go [file path] [number of top lines]`) } filepath := args[1] topLines := defaultTopLines if len(args) == 3 { topLinesParam, err := strconv.Atoi(args[2]) if err != nil { panic("The number of top lines param must be a number") } topLines = topLinesParam } analyser, err := redhat.InitFromFile(filepath) if err != nil { panic("can not init the program due to file is invalid: " + err.Error()) } if err = analyser.AnalyseData(); err != nil { panic("fail to process and analyse data:" + err.Error()) } for _, outputLine := range analyser.Output(topLines) { fmt.Println(outputLine) } }