yats.git

commit afde882c4708403ba71acf27b1791be2fdc52fda

Author: Paolo Lulli <paolo@lulli.net>

Reorganize cli options

 client/main.go | 96 +++++++++++++++++++++++++++------------------------


diff --git a/client/main.go b/client/main.go
index c56a2adcf832d8d44d5d877379e09c543a65d39f..17486917c344f6e7e284799131a3860b37aac484 100644
--- a/client/main.go
+++ b/client/main.go
@@ -38,22 +38,21 @@ 	generatePki := flag.BoolP("csr", "c", false, "Create Certificate Signing Request")
 
 	sourceOption := flag.StringP("source", "s", "", "Source Application")
 
-	isMetricOption := flag.BoolP("metric", "m", false, "Metric Mode")
-	isPositionOption := flag.BoolP("position", "p", false, "Position Mode")
-
 	isShowPermsOption := flag.BoolP("show-permissions", "S", false, "Show User Permissions")
 
-	writeModeOption := flag.BoolP("write", "w", false, "Write Mode")
-
 	fromOption := flag.Int64("from", 0, "From tstamp")
 	toOption := flag.Int64("to", 0, "To tstamp")
 
-	metricNameOption := flag.StringP("metricName", "n", "", "Metric Name")
-	metricValueOption := flag.StringP("value", "v", "", "Metric Value")
 	timestampOption := flag.Int64("timestamp", 0, "Metric/Event TimeStamp")
 
-	eventNameOption := flag.StringP("eventName", "e", "", "Event Name")
-	positionNameOption := flag.StringP("positionName", "x", "", "Position Name")
+	writeEvent := flag.StringP("write-event", "E", "", "Write Event Name")
+	writeMetric := flag.StringP("write-metric", "M", "", "Write Metric Name")
+	metricValue := flag.StringP("metric-value", "v", "", "Metric Value")
+	writePosition := flag.StringP("write-position", "P", "", "Write Position Name")
+
+	listEvents := flag.BoolP("list-events", "e", false, "List Events")
+	listMetrics := flag.StringP("list-metrics", "m", "", "List Metrics with Name")
+	listPositions := flag.StringP("list-positions", "p", "", "List Positions with Name")
 
 	longitudeOption := flag.Float64P("longitude", "o", 0, "Longitude")
 	latitudeOption := flag.Float64P("latitude", "a", 0, "Latitude")
@@ -75,47 +74,54 @@ 		yatsClient.CreateCsr()
 		os.Exit(0)
 	}
 
-	if !*writeModeOption {
-		if *isMetricOption {
-			//fmt.Printf("metricNameOption: %s", *metricNameOption)
-			listResponse, err := yatsClient.MetricList(*sourceOption, *metricNameOption, *fromOption, *toOption)
-			if err == nil {
-				fmt.Printf("%s", listResponse)
-			} else {
-				fmt.Println(err)
-			}
-		} else if *isPositionOption {
-			listResponse := yatsClient.PositionList(*sourceOption, *fromOption, *toOption)
+	if "" != *writeEvent {
+		saveEventResponse, err := yatsClient.EventSave(*writeEvent, *timestampOption)
+		if err == nil {
+			fmt.Printf("%s", saveEventResponse)
+		} else {
+			fmt.Println(err)
+		}
+		os.Exit(0)
+	}
+
+	if "" != *writeMetric {
+		listResponse, err := yatsClient.MetricSave(*writeMetric, *metricValue, *timestampOption)
+		if err == nil {
 			fmt.Printf("%s", listResponse)
 		} else {
-			listEvents := yatsClient.EventList(*sourceOption, *fromOption, *toOption)
-			fmt.Printf("%s", listEvents)
+			fmt.Println(err)
 		}
-	} else {
-		// Write Mode
-		if *isMetricOption {
-			fmt.Printf("metricNameOption: %s", *metricNameOption)
+		os.Exit(0)
+	}
+	if "" != *writePosition {
+		savePositionResponse, err := yatsClient.PositionSave(*writePosition, *latitudeOption, *longitudeOption, *timestampOption)
+		if err == nil {
+			fmt.Printf("%s", savePositionResponse)
+		} else {
+			fmt.Println(err)
+		}
+		os.Exit(0)
+	}
 
-			listResponse, err := yatsClient.MetricSave(*metricNameOption, *metricValueOption, *timestampOption)
-			if err == nil {
-				fmt.Printf("%s", listResponse)
-			} else {
-				fmt.Println(err)
-			}
-		} else if *isPositionOption {
-			savePositionResponse, err := yatsClient.PositionSave(*positionNameOption, *latitudeOption, *longitudeOption, *timestampOption)
-			if err == nil {
-				fmt.Printf("%s", savePositionResponse)
-			} else {
-				fmt.Println(err)
-			}
+	if *listEvents {
+		listEvents := yatsClient.EventList(*sourceOption, *fromOption, *toOption)
+		fmt.Printf("%s", listEvents)
+		os.Exit(0)
+	}
+
+	if "" != *listMetrics {
+		listResponse, err := yatsClient.MetricList(*sourceOption, *listMetrics, *fromOption, *toOption)
+		if err == nil {
+			fmt.Printf("%s", listResponse)
 		} else {
-			saveEventResponse, err := yatsClient.EventSave(*eventNameOption, *timestampOption)
-			if err == nil {
-				fmt.Printf("%s", saveEventResponse)
-			} else {
-				fmt.Println(err)
-			}
+			fmt.Println(err)
 		}
+		os.Exit(0)
+	}
+
+	if "" != *listPositions {
+		listResponse := yatsClient.PositionList(*sourceOption, *fromOption, *toOption)
+		fmt.Printf("%s", listResponse)
+		os.Exit(0)
 	}
 }