@@ -17,19 +17,29 @@ import (
1717
1818 "github.com/arduino/arduino-create-agent/gen/tools"
1919 "github.com/codeclysm/extract"
20- "github.com/sirupsen/logrus"
2120 "github.com/xrash/smetrics"
2221)
2322
23+ // Tools is a client that implements github.com/arduino/arduino-create-agent/gen/tools.Service interface.
24+ // It saves tools in a specified folder with this structure: packager/name/version
25+ // For example:
26+ // folder
27+ // └── arduino
28+ // └── bossac
29+ // ├── 1.6.1-arduino
30+ // │ └── bossac
31+ // └── 1.7.0
32+ // └── bossac
33+ // It requires an Indexes client to list and read package index files: use the Indexes struct
2434type Tools struct {
25- Log * logrus.Logger
2635 Indexes interface {
2736 List (context.Context ) ([]string , error )
2837 Get (context.Context , string ) (Index , error )
2938 }
3039 Folder string
3140}
3241
42+ // Available crawles the downloaded package index files and returns a list of tools that can be installed.
3343func (c * Tools ) Available (ctx context.Context ) (res tools.ToolCollection , err error ) {
3444 list , err := c .Indexes .List (ctx )
3545 if err != nil {
@@ -56,6 +66,7 @@ func (c *Tools) Available(ctx context.Context) (res tools.ToolCollection, err er
5666 return res , nil
5767}
5868
69+ // Installed crawles the Tools Folder and finds the installed tools.
5970func (c * Tools ) Installed (ctx context.Context ) (tools.ToolCollection , error ) {
6071 res := tools.ToolCollection {}
6172
@@ -94,6 +105,8 @@ func (c *Tools) Installed(ctx context.Context) (tools.ToolCollection, error) {
94105 return res , nil
95106}
96107
108+ // Install crawles the Index folder, downloads the specified tool, extracts the archive in the Tools Folder.
109+ // It checks for the Signature specified in the package index.
97110func (c * Tools ) Install (ctx context.Context , payload * tools.ToolPayload ) error {
98111 list , err := c .Indexes .List (ctx )
99112 if err != nil {
@@ -157,6 +170,7 @@ func (c *Tools) install(ctx context.Context, packager string, tool Tool) error {
157170 return nil
158171}
159172
173+ // Remove deletes the tool folder from Tools Folder
160174func (c * Tools ) Remove (ctx context.Context , payload * tools.ToolPayload ) error {
161175 path := filepath .Join (payload .Packager , payload .Name , payload .Version )
162176
0 commit comments