Skip to content

Commit 6ac64ef

Browse files
committed
Added function to retrieve tools path
1 parent d6be8bb commit 6ac64ef

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tools.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
appPath, err := paths.New(os.Args[0]).Abs()
30+
if err != nil {
31+
return nil, err
32+
}
33+
toolPath := appPath.Parent().Join(toolName, toolVersion.String())
34+
if !appPath.IsDir() {
35+
return nil, fmt.Errorf("tool not found: %s@%s", toolName, toolVersion)
36+
}
37+
return toolPath, nil
38+
}

0 commit comments

Comments
 (0)