Browse Source

Add basic parsing of arguments to the program

The program can now run with different arguments.
Oz Tiram 5 years ago
parent
commit
ecca586a5a
1 changed files with 20 additions and 1 deletions
  1. 20 1
      cmd/main.go

+ 20 - 1
cmd/main.go

@@ -1,10 +1,29 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"github.com/oz123/gupta"
+	"time"
 )
 
 func main() {
-	fmt.Println(gupta.Hello())
+	var freq int
+	var partition, netInterface string
+	var load, memory, cpu bool
+
+	flag.IntVar(&freq, "frequency", 5, "Frequency of polling in secods")
+	flag.IntVar(&freq, "f", 5, "Frequency of polling in secods")
+	flag.BoolVar(&memory, "m", false, "Poll memory")
+	flag.BoolVar(&load, "l", false, "Poll load")
+	flag.BoolVar(&cpu, "c", false, "poll CPU usage")
+	flag.StringVar(&partition, "p", "", "Poll disk usage (partition)")
+	flag.StringVar(&netInterface, "n", "", "Network usage (interface)")
+
+	flag.Parse()
+
+	for true {
+		fmt.Println(gupta.Hello())
+		time.Sleep(time.Duration(freq) * time.Second)
+	}
 }