From ae2c2dfbe2b101a9ba1d8c328c7238875004b719 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Mon, 23 Dec 2024 02:29:45 +0200 Subject: [PATCH] feat: add bin check to group --- installer/brew_installer.go | 1 - installer/group_installer.go | 32 +++++++++++++++++++++++++++++++- installer/installer.go | 4 ++-- sofmani.yml | 13 +++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/installer/brew_installer.go b/installer/brew_installer.go index 2d0968f..9eb74d8 100644 --- a/installer/brew_installer.go +++ b/installer/brew_installer.go @@ -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 { diff --git a/installer/group_installer.go b/installer/group_installer.go index 8a7c76d..f3be2a7 100644 --- a/installer/group_installer.go +++ b/installer/group_installer.go @@ -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, diff --git a/installer/installer.go b/installer/installer.go index 1c54475..505e960 100644 --- a/installer/installer.go +++ b/installer/installer.go @@ -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) } diff --git a/sofmani.yml b/sofmani.yml index a6d309e..b53e2ce 100644 --- a/sofmani.yml +++ b/sofmani.yml @@ -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'