diff --git a/README.md b/README.md index b260a0fd1..651bdd2b2 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ $ launchctl unload ~/Library/LaunchAgents/ArduinoCreateAgent.plist 2. Select the .config dir in your home ![Select the .config dir in your home](https://raw.githubusercontent.com/arduino/arduino-create-agent/devel/images/linux/02.png) -3. Select the autostart dir +3. Select the autostart dir ![Select the autostart dir](https://raw.githubusercontent.com/arduino/arduino-create-agent/devel/images/linux/03.png) 4. Move the file to the trash @@ -248,7 +248,7 @@ You can receive output from the serial port by listening to messages like this: ### Download a tool You can download a tool on the computer with a command like - download avrdude + downloadtool avrdude 6.0.1-arduino5 replace receiving a reply like @@ -259,6 +259,13 @@ receiving a reply like } ``` +The syntax of the command is: + + downloadtool {{name}} {{version}} {{behaviour}} + +where `version` can be a version number of the string "latest", and `behaviour` can be +"keep" (which skip the download if the tool already exists) and "replace" (which will download it again). + ### Upload You can upload a binary sketch to a board connected to a port with a POST request to be made at the http endpoint. diff --git a/hub.go b/hub.go index 9fcc94430..17363e48f 100755 --- a/hub.go +++ b/hub.go @@ -190,26 +190,38 @@ func checkCmd(m []byte) { go spList(false) go spList(true) } else if strings.HasPrefix(sl, "downloadtool") { - args := strings.Split(s, " ") - if len(args) > 1 { - go func() { - var err error - if args[1] == "avrdude" { - err = Tools.Download(args[1], "6.0.1-arduino5", "keep") - } else { - err = Tools.Download(args[1], "latest", "keep") - } - if err != nil { - mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()} - mapB, _ := json.Marshal(mapD) - h.broadcastSys <- mapB - } else { - mapD := map[string]string{"DownloadStatus": "Success", "Msg": "Map Updated"} - mapB, _ := json.Marshal(mapD) - h.broadcastSys <- mapB - } - }() - } + go func() { + args := strings.Split(s, " ") + var tool, toolVersion, behaviour string + toolVersion = "latest" + behaviour = "keep" + if len(args) <= 1 { + mapD := map[string]string{"DownloadStatus": "Error", "Msg": "Not enough arguments"} + mapB, _ := json.Marshal(mapD) + h.broadcastSys <- mapB + return + } + if len(args) > 1 { + tool = args[1] + } + if len(args) > 2 { + toolVersion = args[2] + } + if len(args) > 3 { + behaviour = args[3] + } + + err := Tools.Download(tool, toolVersion, behaviour) + if err != nil { + mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()} + mapB, _ := json.Marshal(mapD) + h.broadcastSys <- mapB + } else { + mapD := map[string]string{"DownloadStatus": "Success", "Msg": "Map Updated"} + mapB, _ := json.Marshal(mapD) + h.broadcastSys <- mapB + } + }() } else if strings.HasPrefix(sl, "bufferalgorithm") { go spBufferAlgorithms() } else if strings.HasPrefix(sl, "log") {