findTool find matched tool with name and version.
(ctx context.Context, nameVersion string)
| 262 | |
| 263 | // findTool find matched tool with name and version. |
| 264 | func (b BuildTools) findTool(ctx context.Context, nameVersion string) (*BuildTool, error) { |
| 265 | toolName, toolVersion := b.parseNameVersion(nameVersion) |
| 266 | |
| 267 | for index, tool := range b.BuildTools { |
| 268 | if tool.Name != toolName { |
| 269 | continue |
| 270 | } |
| 271 | |
| 272 | if toolVersion == "" { |
| 273 | if !tool.Default { // No version specified - must use default. |
| 274 | return nil, fmt.Errorf("%s is found, but no version specified", toolName) |
| 275 | } |
| 276 | } else if tool.Version != toolVersion { |
| 277 | continue |
| 278 | } |
| 279 | |
| 280 | // Matched tool found. |
| 281 | b.BuildTools[index].ctx = ctx |
| 282 | return &b.BuildTools[index], nil |
| 283 | } |
| 284 | |
| 285 | return nil, fmt.Errorf("tool %s is not found", nameVersion) |
| 286 | } |
| 287 | |
| 288 | func (b BuildTools) contains(name string) bool { |
| 289 | toolName, _ := b.parseNameVersion(name) |
no test coverage detected