feat: pipx installer

This commit is contained in:
2025-01-21 00:32:24 +02:00
parent 124e21f7c8
commit fcebf7c176
5 changed files with 84 additions and 0 deletions

View File

@@ -218,6 +218,10 @@ For a full list with all the supported options, see [the docs](./docs/installer-
- Installs packages using apt install.
- **`pipx`**
- Installs packages using pipx.
---
## 📂 Example Workflow

View File

@@ -40,6 +40,7 @@ const (
InstallerTypeNpm InstallerType = "npm"
InstallerTypePnpm InstallerType = "pnpm"
InstallerTypeYarn InstallerType = "yarn"
InstallerTypePipx InstallerType = "pipx"
InstallerTypeManifest InstallerType = "manifest"
)

View File

@@ -177,6 +177,9 @@ These fields are shared by all installer types. Some fields may vary in behavior
- **`apt`**
- **Description**: Installs packages using apt install.
- **`pipx`**
- **Description**: Installs packages using pipx.
## Installer Examples
All of these examples should be usable, but don't count on them being maintained. Why not look at

View File

@@ -30,6 +30,8 @@ func GetInstaller(config *appconfig.AppConfig, data *appconfig.InstallerData) (e
return nil, NewNpmInstaller(config, data)
case appconfig.InstallerTypeApt:
return nil, NewAptInstaller(config, data)
case appconfig.InstallerTypePipx:
return nil, NewPipxInstaller(config, data)
case appconfig.InstallerTypeGit:
return nil, NewGitInstaller(config, data)
case appconfig.InstallerTypeManifest:

View File

@@ -0,0 +1,74 @@
package installer
import (
"github.com/chenasraf/sofmani/appconfig"
"github.com/chenasraf/sofmani/utils"
)
type PipxInstaller struct {
Config *appconfig.AppConfig
Info *appconfig.InstallerData
}
type PipxOpts struct {
//
}
// Install implements IInstaller.
func (i *PipxInstaller) Install() error {
name := *i.Info.Name
return utils.RunCmdPassThrough(i.Info.Environ(), "pipx", "install", name)
}
// Update implements IInstaller.
func (i *PipxInstaller) Update() error {
return utils.RunCmdPassThrough(i.Info.Environ(), "pipx", "upgrade", *i.Info.Name)
}
// CheckNeedsUpdate implements IInstaller.
func (i *PipxInstaller) CheckNeedsUpdate() (error, bool) {
if i.GetData().CheckHasUpdate != nil {
return utils.RunCmdGetSuccess(i.Info.Environ(), utils.GetOSShell(i.GetData().EnvShell), utils.GetOSShellArgs(*i.GetData().CheckHasUpdate)...)
}
err, success := utils.RunCmdGetSuccess(i.Info.Environ(), "pipx", "upgrade", "--pip-args=--dry-run", *i.Info.Name)
if err != nil {
return err, false
}
return nil, !success
}
// CheckIsInstalled implements IInstaller.
func (i *PipxInstaller) CheckIsInstalled() (error, bool) {
return utils.RunCmdGetSuccess(i.Info.Environ(), utils.GetShellWhich(), i.GetBinName())
}
// GetData implements IInstaller.
func (i *PipxInstaller) GetData() *appconfig.InstallerData {
return i.Info
}
func (i *PipxInstaller) GetOpts() *PipxOpts {
opts := &PipxOpts{}
info := i.Info
if info.Opts != nil {
//
}
return opts
}
func (i *PipxInstaller) GetBinName() string {
info := i.GetData()
if info.BinName != nil && len(*info.BinName) > 0 {
return *info.BinName
}
return *info.Name
}
func NewPipxInstaller(cfg *appconfig.AppConfig, installer *appconfig.InstallerData) *PipxInstaller {
i := &PipxInstaller{
Config: cfg,
Info: installer,
}
return i
}