Skip to content

Commit 1b22b57

Browse files
committed
Add docs about tools
1 parent f21d3ed commit 1b22b57

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

docs/pkgs.html

+45
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,51 @@ <h2>Remove Indexes</h2>
5252
<p>You can now check if the new package_index was removed by repeating List Indexes.</p>
5353

5454

55+
<h1>Tools</h1>
56+
<p>A tool is an executable that can be used to program a board.</p>
57+
58+
<p>tools are saved in the folder <code>~/.arduino-create</code> with a structure like <code>{packager}/{name}/{version}</code></p>
59+
60+
<h2>List Available Tools</h2>
61+
<p>You can list the available tools that could be installed from an index with this simple GET. (Remember to add
62+
indexes)</p>
63+
<textarea cols="100" id="toolsAvailable">
64+
fetch('http://localhost:8991/v2/pkgs/tools/available')
65+
</textarea><br>
66+
<textarea cols="100" rows="10" id="toolsAvailableRes"></textarea><br>
67+
<button onclick="tryCode('toolsAvailable', 'toolsAvailableRes');">Try</button>
68+
69+
<h2>List Installed Tools</h2>
70+
<p>You can list the tools installed in the system with this simple GET</p>
71+
<textarea cols="100" id="toolsList">
72+
fetch('http://localhost:8991/v2/pkgs/tools/installed')
73+
</textarea><br>
74+
<textarea cols="100" rows="10" id="toolsListRes"></textarea><br>
75+
<button onclick="tryCode('toolsList', 'toolsListRes');">Try</button>
76+
77+
78+
<h2>Install a tool from an index file</h2>
79+
<p>You can install one of the available tools with a PUT request</p>
80+
<textarea cols="100" rows="5" id="toolsInstall">
81+
fetch('http://localhost:8991/v2/pkgs/tools/installed', {
82+
method: "PUT",
83+
body: '{"name":"sketchUploader","version":"1.6.2+1.0","packager":"Intel"}'
84+
})
85+
</textarea><br>
86+
<textarea cols="100" rows="10" id="toolsInstallRes"></textarea><br>
87+
<button onclick="tryCode('toolsInstall', 'toolsInstallRes');">Try</button>
88+
89+
90+
<h2>Remove an installed tool</h2>
91+
<p>You can remove one of the installed tools with a DELETE request</p>
92+
<textarea cols="100" rows="5" id="toolsRemove">
93+
fetch('http://localhost:8991/v2/pkgs/tools/installed/Intel/sketchUploader/1.6.2+1.0', {
94+
method: "DELETE",
95+
})
96+
</textarea><br>
97+
<textarea cols="100" rows="10" id="toolsRemoveRes"></textarea><br>
98+
<button onclick="tryCode('toolsRemove', 'toolsRemoveRes');">Try</button>
99+
55100
</body>
56101

57102
<script>

v2/http.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ func Server(home string) http.Handler {
3030
Folder: filepath.Join(home, "indexes"),
3131
}
3232
indexesEndpoints := indexessvc.NewEndpoints(&indexesSvc)
33-
indexesServer := indexessvr.New(indexesEndpoints, mux, goahttp.RequestDecoder, goahttp.ResponseEncoder, errorHandler(logger))
33+
indexesServer := indexessvr.New(indexesEndpoints, mux, goahttp.RequestDecoder,
34+
goahttp.ResponseEncoder, errorHandler(logger))
3435
indexessvr.Mount(mux, indexesServer)
3536

3637
// Mount tools
37-
toolsSvc := pkgs.Tools{}
38+
toolsSvc := pkgs.Tools{
39+
Folder: home,
40+
Indexes: &indexesSvc,
41+
}
3842
toolsEndpoints := toolssvc.NewEndpoints(&toolsSvc)
3943
toolsServer := toolssvr.New(toolsEndpoints, mux, goahttp.RequestDecoder, goahttp.ResponseEncoder, errorHandler(logger))
4044
toolssvr.Mount(mux, toolsServer)

v2/pkgs/tools.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,19 @@ func (c *Tools) Installed(ctx context.Context) (tools.ToolCollection, error) {
8080
if !packager.IsDir() {
8181
continue
8282
}
83+
8384
// Find tools
8485
toolss, err := ioutil.ReadDir(filepath.Join(c.Folder, packager.Name()))
8586
if err != nil {
8687
return nil, err
8788
}
89+
8890
for _, tool := range toolss {
8991
// Find versions
90-
versions, err := ioutil.ReadDir(filepath.Join(c.Folder, packager.Name(), tool.Name()))
92+
path := filepath.Join(c.Folder, packager.Name(), tool.Name())
93+
versions, err := ioutil.ReadDir(path)
9194
if err != nil {
92-
return nil, err
95+
continue // we ignore errors because the folders could be dirty
9396
}
9497

9598
for _, version := range versions {

0 commit comments

Comments
 (0)