Skip to content

Commit

Permalink
use binary names instead of package names
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanhawari committed Jan 21, 2025
1 parent 154c3a8 commit a251782
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ stew config # Automatically updates the stew.config.json
You can configure 2 aspects of `stew`:
1. The `stewPath`: this is where `stew` data is stored.
2. The `stewBinPath`: this is where `stew` installs binaries
3. `excludeFromUpgradeAll`: this is the list of binaries that you don't want to keep upgraded during `stew upgrade --all`, perhaps if they have their own built in upgrade feature, or you want to pin a specific version.
3. `excludeFromUpgradeAll`: this is the list of binaries that you don't want to be upgraded during `stew upgrade --all`, perhaps because they have their own built in upgrade feature or because you want to pin a specific version.

The default locations for the `stewPath` and `stewBinPath` are:
| | Linux/macOS | Windows |
Expand Down
6 changes: 3 additions & 3 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func Config() {
stew.CatchAndExit(err)
return
}
_, _, _, systemInfo, _ := stew.Initialize()
installedPackages, err := stew.ReadStewLockFileContents(systemInfo.StewLockFilePath)
stew.CatchAndExit(err)

config, err := stew.ReadStewConfigJSON(stewConfigFilePath)
stew.CatchAndExit(err)
systemInfo := stew.NewSystemInfo(config)
installedPackages, err := stew.ReadStewLockFileContents(systemInfo.StewLockFilePath)
stew.CatchAndExit(err)
newStewPath, newStewBinPath, newExcludedFromUpgradeAll, err := stew.PromptConfig(config.StewPath, config.StewBinPath, installedPackages, config.ExcludedFromUpgradeAll)
stew.CatchAndExit(err)

Expand Down
11 changes: 10 additions & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ func List(cliTagsFlag bool) {
}

for _, pkg := range lockFile.Packages {
fmt.Println(stew.GetPackageDisplayName(pkg, cliTagsFlag))
switch pkg.Source {
case "other":
fmt.Println(pkg.URL)
case "github":
if cliTagsFlag {
fmt.Println(pkg.Owner + "/" + pkg.Repo + "@" + pkg.Tag)
} else {
fmt.Println(pkg.Owner + "/" + pkg.Repo)
}
}
}
}
12 changes: 4 additions & 8 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,12 @@ func upgradeAll(userOS, userArch string, lockFile stew.LockFile, systemInfo stew
stew.CatchAndExit(err)
stewConfig, err := stew.ReadStewConfigJSON(stewConfigFilePath)
stew.CatchAndExit(err)
excludedPackages := stewConfig.ExcludedFromUpgradeAll
excludedBinaries := stewConfig.ExcludedFromUpgradeAll

for _, pkg := range lockFile.Packages {
if pkg.Source != "other" {
// Skip upgrading explicitly excluded packages
pkgName := stew.GetPackageDisplayName(pkg, false)
if _, packageIsExcluded := stew.Contains(excludedPackages, pkgName); packageIsExcluded {
fmt.Printf("%v (excluded)\n", constants.YellowColor(pkgName))
continue
}
if _, packageIsExcluded := stew.Contains(excludedBinaries, pkg.Binary); packageIsExcluded {
fmt.Printf("%v (excluded)\n", constants.YellowColor(pkg.Binary))
continue
}
if err := upgradeOne(pkg.Binary, userOS, userArch, lockFile, systemInfo); err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
17 changes: 10 additions & 7 deletions lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func NewStewConfig(userOS string) (StewConfig, error) {
if err != nil {
return StewConfig{}, err
}
defaultExcludedFromUpgradeAll := []string{}

configExists, err := PathExists(stewConfigFilePath)
if err != nil {
Expand All @@ -153,8 +154,13 @@ func NewStewConfig(userOS string) (StewConfig, error) {
if stewConfig.StewBinPath == "" {
stewConfig.StewBinPath = defaultStewBinPath
}

if len(stewConfig.ExcludedFromUpgradeAll) == 0 {
stewConfig.ExcludedFromUpgradeAll = defaultExcludedFromUpgradeAll
}
} else {
selectedStewPath, selectedStewBinPath, excludedFromUpgradeAll, err := PromptConfig(defaultStewPath, defaultStewBinPath, []PackageData{}, []string{})
defaultInstalledPackages := []PackageData{}
selectedStewPath, selectedStewBinPath, excludedFromUpgradeAll, err := PromptConfig(defaultStewPath, defaultStewBinPath, defaultInstalledPackages, defaultExcludedFromUpgradeAll)
if err != nil {
return StewConfig{}, err
}
Expand Down Expand Up @@ -249,17 +255,14 @@ func PromptConfig(suggestedStewPath string, suggestedStewBinPath string, install
}
excludedFromUpgradeAll := []string{}
if len(installedPackages) != 0 {
packagesNotInstalledFromUrl := []string{}
installedBinaryNames := []string{}
for _, pkg := range installedPackages {
if pkg.Source != "other" {
packagesNotInstalledFromUrl = append(packagesNotInstalledFromUrl, GetPackageDisplayName(pkg, false))
}
installedBinaryNames = append(installedBinaryNames, pkg.Binary)
}
packages, err := PromptMultiSelect("Select any packages that you do not wish to be upgraded during stew upgrade --all.", packagesNotInstalledFromUrl, excludedPackages)
excludedFromUpgradeAll, err = PromptMultiSelect("Select any packages that you do not wish to be upgraded during stew upgrade --all.", installedBinaryNames, excludedPackages)
if err != nil {
return "", "", []string{}, err
}
excludedFromUpgradeAll = append(excludedFromUpgradeAll, packages...)
}

fullStewPath, err := ResolvePath(inputStewPath)
Expand Down
14 changes: 0 additions & 14 deletions lib/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,3 @@ func ResolvePath(filePath string) (string, error) {

return resolvedPath, nil
}

// GetPackageDisplayName will provide the display name for a given package
func GetPackageDisplayName(pkg PackageData, withTag bool) string {
switch pkg.Source {
case "github":
if withTag {
return pkg.Owner + "/" + pkg.Repo + "@" + pkg.Tag
} else {
return pkg.Owner + "/" + pkg.Repo
}
default:
return pkg.URL
}
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func main() {
},
{
Name: "config",
Usage: "Configure the stew file paths and upgrade-excluded binaries using an interactive UI. [Ex: stew config]",
Usage: "Configure stew using an interactive UI. [Ex: stew config]",
Action: func(c *cli.Context) error {
cmd.Config()
return nil
Expand Down

0 comments on commit a251782

Please sign in to comment.