Skip to content

Commit baed5fc

Browse files
authored
Merge pull request #1 from arduino/tools_helper
Added function to retrieve tools path
2 parents 2effbfc + eefc0dc commit baed5fc

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tools.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// fwuploader-plugin-helper
2+
// Copyright (c) 2023 Arduino LLC. All right reserved.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published
6+
// by the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
package helper
18+
19+
import (
20+
"fmt"
21+
"os"
22+
23+
"github.com/arduino/go-paths-helper"
24+
semver "go.bug.st/relaxed-semver"
25+
)
26+
27+
// FindToolPath retrieve the path to the given tool, if available, otherwise returns an error
28+
func FindToolPath(toolName string, toolVersion *semver.Version) (*paths.Path, error) {
29+
executablePath, err := os.Executable()
30+
if err != nil {
31+
return nil, err
32+
}
33+
toolsDir := paths.New(executablePath).Parent()
34+
toolPath := toolsDir.Join(toolName, toolVersion.String())
35+
if !toolPath.IsDir() {
36+
return nil, fmt.Errorf("tool not found: %s@%s", toolName, toolVersion)
37+
}
38+
return toolPath, nil
39+
}

0 commit comments

Comments
 (0)