mirror of
https://github.com/chenasraf/sofmani.git
synced 2026-05-17 17:28:04 +00:00
feat: add bin check to group
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
13
sofmani.yml
13
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'
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user