feat: add bin check to group

This commit is contained in:
2024-12-23 02:29:45 +02:00
parent 8aecf9af36
commit ae2c2dfbe2
4 changed files with 46 additions and 4 deletions

View File

@@ -69,7 +69,6 @@ func (i *BrewInstaller) CheckNeedsUpdate() (error, bool) {
// CheckIsInstalled implements IInstaller.
func (i *BrewInstaller) CheckIsInstalled() (error, bool) {
// cmd := exec.Command("brew", "list", i.Info.Name)
cmd := exec.Command("which", i.GetBinName())
err := cmd.Run()
if err != nil {

View File

@@ -1,6 +1,8 @@
package installer
import (
"os/exec"
"github.com/chenasraf/sofmani/appconfig"
"github.com/chenasraf/sofmani/logger"
)
@@ -10,6 +12,10 @@ type GroupInstaller struct {
Info *appconfig.Installer
}
type GroupOpts struct {
BinName *string
}
// Install implements IInstaller.
func (i *GroupInstaller) Install() error {
logger.Debug("Installing group %s", i.Info.Name)
@@ -35,7 +41,12 @@ func (i *GroupInstaller) CheckNeedsUpdate() (error, bool) {
// CheckIsInstalled implements IInstaller.
func (i *GroupInstaller) CheckIsInstalled() (error, bool) {
return nil, false
cmd := exec.Command("which", i.GetBinName())
err := cmd.Run()
if err != nil {
return nil, false
}
return nil, true
}
// GetInfo implements IInstaller.
@@ -43,6 +54,25 @@ func (i *GroupInstaller) GetInfo() *appconfig.Installer {
return i.Info
}
func (i *GroupInstaller) GetOpts() *GroupOpts {
opts := &GroupOpts{}
info := i.Info
if info.Opts != nil {
if binName, ok := (*info.Opts)["bin_name"].(string); ok {
opts.BinName = &binName
}
}
return opts
}
func (i *GroupInstaller) GetBinName() string {
opts := i.GetOpts()
if opts.BinName != nil && len(*opts.BinName) > 0 {
return *opts.BinName
}
return i.Info.Name
}
func NewGroupInstaller(cfg *appconfig.AppConfig, installer *appconfig.Installer) *GroupInstaller {
return &GroupInstaller{
Config: cfg,

View File

@@ -18,10 +18,10 @@ type IInstaller interface {
func GetInstaller(config *appconfig.AppConfig, installer *appconfig.Installer) (error, IInstaller) {
switch installer.Type {
case appconfig.InstallerTypeBrew:
return nil, NewBrewInstaller(config, installer)
case appconfig.InstallerTypeGroup:
return nil, NewGroupInstaller(config, installer)
case appconfig.InstallerTypeBrew:
return nil, NewBrewInstaller(config, installer)
case appconfig.InstallerTypeShell:
return nil, NewShellInstaller(config, installer)
}

View File

@@ -33,5 +33,18 @@ install:
curl -fsSL https://fnm.vercel.app/install | bash
fnm install --lts
fnm use lts-latest
- name: pyenv
type: group
steps:
- name: pyenv
type: brew
platforms:
only: ['macos']
- name: pyenv
type: shell
platforms:
only: ['linux']
opts:
command: 'curl https://pyenv.run | bash'