From 1b022402a9d9658897db934741c1e54dafa678a9 Mon Sep 17 00:00:00 2001 From: Albert Nisbet Date: Sat, 16 May 2020 18:11:30 +1200 Subject: [PATCH] Remove client ID default and make password param lowercase (#7) * Remove default for client ID param * Make password flag lower case --- main.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 609c5b8..c3c6a80 100644 --- a/main.go +++ b/main.go @@ -74,9 +74,9 @@ func main() { commandPtr := flag.String("c", "", "Command to run when any message received on topic") topicPtr := flag.String("t", "computer/command", "Topic to subscribe to") brokerPtr := flag.String("h", "127.0.0.1:1883", "Address and port of MQTT broker") - clientIDPtr := flag.String("i", "mqcontrol", "ID to use for this client") + clientIDPtr := flag.String("i", "", "ID to use for this client") userPtr := flag.String("u", "", "Username for MQTT connection") - passwordPtr := flag.String("P", "", "Password for MQTT connection") + passwordPtr := flag.String("p", "", "Password for MQTT connection") flag.Parse() @@ -101,6 +101,12 @@ func main() { flag.PrintDefaults() os.Exit(1) } + if conf.ClientID == "" { + fmt.Println("No client ID argument provided") + fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0]) + flag.PrintDefaults() + os.Exit(1) + } r := csv.NewReader(strings.NewReader(conf.Command)) r.Comma = ' ' @@ -117,7 +123,7 @@ func main() { opts.SetAutoReconnect(true) opts.SetConnectionLostHandler(func(c MQTT.Client, err error) { - log.Println("Client connection lost unexpectedly") + log.Println("Client connection lost unexpectedly.") }) msg := make(chan []byte)