Skip to content

Commit 9874642

Browse files
authored
Merge pull request #121 from arduino/download_versions
Make it possible for users to download a specific version of a tool
2 parents b199b1a + 3a27d63 commit 9874642

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ $ launchctl unload ~/Library/LaunchAgents/ArduinoCreateAgent.plist
5555
2. Select the .config dir in your home
5656

5757
![Select the .config dir in your home](https://raw.githubusercontent.com/arduino/arduino-create-agent/devel/images/linux/02.png)
58-
3. Select the autostart dir
58+
3. Select the autostart dir
5959

6060
![Select the autostart dir](https://raw.githubusercontent.com/arduino/arduino-create-agent/devel/images/linux/03.png)
6161
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:
248248
### Download a tool
249249
You can download a tool on the computer with a command like
250250
251-
download avrdude
251+
downloadtool avrdude 6.0.1-arduino5 replace
252252
253253
receiving a reply like
254254
@@ -259,6 +259,13 @@ receiving a reply like
259259
}
260260
```
261261
262+
The syntax of the command is:
263+
264+
downloadtool {{name}} {{version}} {{behaviour}}
265+
266+
where `version` can be a version number of the string "latest", and `behaviour` can be
267+
"keep" (which skip the download if the tool already exists) and "replace" (which will download it again).
268+
262269
### Upload
263270
You can upload a binary sketch to a board connected to a port with a POST request to be made at the http endpoint.
264271

hub.go

+32-20
Original file line numberDiff line numberDiff line change
@@ -190,26 +190,38 @@ func checkCmd(m []byte) {
190190
go spList(false)
191191
go spList(true)
192192
} else if strings.HasPrefix(sl, "downloadtool") {
193-
args := strings.Split(s, " ")
194-
if len(args) > 1 {
195-
go func() {
196-
var err error
197-
if args[1] == "avrdude" {
198-
err = Tools.Download(args[1], "6.0.1-arduino5", "keep")
199-
} else {
200-
err = Tools.Download(args[1], "latest", "keep")
201-
}
202-
if err != nil {
203-
mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()}
204-
mapB, _ := json.Marshal(mapD)
205-
h.broadcastSys <- mapB
206-
} else {
207-
mapD := map[string]string{"DownloadStatus": "Success", "Msg": "Map Updated"}
208-
mapB, _ := json.Marshal(mapD)
209-
h.broadcastSys <- mapB
210-
}
211-
}()
212-
}
193+
go func() {
194+
args := strings.Split(s, " ")
195+
var tool, toolVersion, behaviour string
196+
toolVersion = "latest"
197+
behaviour = "keep"
198+
if len(args) <= 1 {
199+
mapD := map[string]string{"DownloadStatus": "Error", "Msg": "Not enough arguments"}
200+
mapB, _ := json.Marshal(mapD)
201+
h.broadcastSys <- mapB
202+
return
203+
}
204+
if len(args) > 1 {
205+
tool = args[1]
206+
}
207+
if len(args) > 2 {
208+
toolVersion = args[2]
209+
}
210+
if len(args) > 3 {
211+
behaviour = args[3]
212+
}
213+
214+
err := Tools.Download(tool, toolVersion, behaviour)
215+
if err != nil {
216+
mapD := map[string]string{"DownloadStatus": "Error", "Msg": err.Error()}
217+
mapB, _ := json.Marshal(mapD)
218+
h.broadcastSys <- mapB
219+
} else {
220+
mapD := map[string]string{"DownloadStatus": "Success", "Msg": "Map Updated"}
221+
mapB, _ := json.Marshal(mapD)
222+
h.broadcastSys <- mapB
223+
}
224+
}()
213225
} else if strings.HasPrefix(sl, "bufferalgorithm") {
214226
go spBufferAlgorithms()
215227
} else if strings.HasPrefix(sl, "log") {

0 commit comments

Comments
 (0)