|
| 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