Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tools/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func InstallTool(logger *log.Logger, tool Tool, installPath string) (err error)
return pkgerrors.WithStack(pkgerrors.WithMessage(err, fmt.Sprintf("%s binary is not a valid file path", tool.BinaryPath())))
}

logger.Printf("Using %q binary %s", tool.BinaryName(), tool.BinaryPath())
logger.Printf("Using %q binary %s", tool.ID(), tool.BinaryPath())

return nil
}
Expand All @@ -64,7 +64,7 @@ func InstallTool(logger *log.Logger, tool Tool, installPath string) (err error)
}

// Make sure only one process is installing a tool at the same time.
lock, err := lockfile.New(filepath.Join(installPath, "install"+tool.BinaryName()+".lock"))
lock, err := lockfile.New(filepath.Join(installPath, "install"+tool.ID()+".lock"))
if err != nil {
return pkgerrors.WithStack(err)
}
Expand All @@ -73,7 +73,7 @@ func InstallTool(logger *log.Logger, tool Tool, installPath string) (err error)
break
}

logger.Printf("Try to lock %q for installing %q but need to wait for another process", installPath, tool.BinaryName())
logger.Printf("Try to lock %q for installing %q but need to wait for another process", installPath, tool.ID())
time.Sleep(time.Second)
}
defer func() {
Expand All @@ -100,7 +100,7 @@ func InstallTool(logger *log.Logger, tool Tool, installPath string) (err error)

// Check if the binary can already be used.
if toolPath, err := exec.LookPath(tool.BinaryName()); err == nil {
logger.Printf("Checking %q binary %q version", tool.BinaryName(), toolPath)
logger.Printf("Checking %q binary %q version", tool.ID(), toolPath)

err := tool.CheckVersion(logger, toolPath)
if err == nil || !pkgerrors.Is(err, ErrToolVersionOutdated) {
Expand All @@ -109,14 +109,14 @@ func InstallTool(logger *log.Logger, tool Tool, installPath string) (err error)

// If the binary got installed by the user, let the user handle the update.
if filepath.Dir(toolPath) != installPath {
return pkgerrors.WithStack(fmt.Errorf("%q binary outdated, need at least %q", tool.BinaryName(), tool.RequiredVersion()))
return pkgerrors.WithStack(fmt.Errorf("%q binary outdated, need at least %q", tool.ID(), tool.RequiredVersion()))
}

logger.Printf("Updating %q to %q", tool.BinaryName(), tool.RequiredVersion())
logger.Printf("Updating %q to %q", tool.ID(), tool.RequiredVersion())
}

// Install the tool as it is either outdated or not installed at all.
logger.Printf("Install %q to %q", tool.BinaryName(), installPath)
logger.Printf("Install %q to %q", tool.ID(), installPath)
if err := tool.Install(logger, installPath); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions tools/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func ValidateInstallTool(t *testing.T, tool Tool) {
logOutput, logger := log.Buffer()
require.NoError(t, InstallTool(logger, tool, temporaryPath))

require.Contains(t, logOutput.String(), fmt.Sprintf(`Install %q to`, tool.BinaryName()))
require.Contains(t, logOutput.String(), fmt.Sprintf(`Install %q to`, tool.ID()))
toolPath, err := exec.LookPath(tool.BinaryName())
require.NoError(t, err)
require.NotEmpty(t, toolPath)
Expand All @@ -46,7 +46,7 @@ func ValidateInstallTool(t *testing.T, tool Tool) {
logOutput, logger := log.Buffer()
require.NoError(t, InstallTool(logger, tool, temporaryPath))

require.NotContains(t, logOutput.String(), fmt.Sprintf(`Install %q to`, tool.BinaryName()))
require.NotContains(t, logOutput.String(), fmt.Sprintf(`Install %q to`, tool.ID()))
toolPath, err := exec.LookPath(tool.BinaryName())
require.NoError(t, err)
require.NotEmpty(t, toolPath)
Expand Down
5 changes: 5 additions & 0 deletions tools/ollama.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func NewOllama() Tool {

var _ Tool = &Ollama{}

// ID returns the unique ID of this tool.
func (*Ollama) ID() (id string) {
return "ollama"
}

// BinaryName returns the name of the tool's binary.
func (*Ollama) BinaryName() string {
return "ollama" + osutil.BinaryExtension()
Expand Down
5 changes: 5 additions & 0 deletions tools/symflower.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func NewSymflower() Tool {

var _ Tool = &symflower{}

// ID returns the unique ID of this tool.
func (*symflower) ID() (id string) {
return "symflower"
}

// BinaryName returns the name of the tool's binary.
func (*symflower) BinaryName() string {
return "symflower" + osutil.BinaryExtension()
Expand Down
8 changes: 5 additions & 3 deletions tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var Tools = map[string]Tool{}

// Register adds a tool to the common tool list.
func Register(tool Tool) {
id := tool.BinaryName()
id := tool.ID()
if _, ok := Tools[id]; ok {
panic(pkgerrors.WithMessage(pkgerrors.New("tool was already registered"), id))
}
Expand All @@ -26,6 +26,8 @@ func Register(tool Tool) {

// Tool defines an external tool.
type Tool interface {
// ID returns the unique ID of this tool.
ID() (id string)
// BinaryName returns the name of the tool's binary.
BinaryName() string
// BinaryPath returns the file path of the tool's binary or the command name that should be executed.
Expand All @@ -52,12 +54,12 @@ func InstallAll(logger *log.Logger, installPath string) (err error) {
if err := InstallTool(logger, tool, installPath); err != nil {
// Log if a tool is not supported by the operating system, but do not fail as it is not a necessary tool.
if pkgerrors.Is(err, ErrUnsupportedOperatingSystem) {
logger.Printf("WARNING: tool %s is not supported by the operating system", tool.BinaryName())
logger.Printf("WARNING: tool %s is not supported by the operating system", tool.ID())

continue
}

err = pkgerrors.WithStack(pkgerrors.WithMessage(err, fmt.Sprintf("cannot install %q", tool.BinaryName())))
err = pkgerrors.WithStack(pkgerrors.WithMessage(err, fmt.Sprintf("cannot install %q", tool.ID())))
installErrors = append(installErrors, err)
}
}
Expand Down