Skip to content

Commit

Permalink
feat: add greedy flag for casks
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed May 22, 2022
1 parent 0059239 commit 4aa2bd8
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
dist
covprofile
dist
vendor
6 changes: 3 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
builds:
- goos:
- linux
- darwin
- windows
- linux
- darwin
- windows

brews:
- tap:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v3.2.0 (2022-05-21)

- Adds a `--greedy` CLI flag so casks can be updated even if they have a UI "auto-update" feature (helps keep Homebrew app versions synced better with what they actually are)

## v3.1.3 (2022-03-23)

- Corrects project namespace by appending `/v3`
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Options:
Update your Homebrew instance.
--force
Forces actions such as backing up even when there are errors. (Brew only)
-greedy
Force updates to casks that have auto-update capabilities in their respective UIs.
```

## Development
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
)

require (
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/BurntSushi/toml v1.1.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/justintime50/mockcmd v0.3.0 h1:ifEMnpeUHrnWulgDu3AzfehaWWGCsHj9zbGbabw+Czs=
github.com/justintime50/mockcmd v0.3.0/go.mod h1:laf0jpehca2YLCiBUZZ508uc6Y1WLzT5Lqspg25KHoI=
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ func main() {
brewUpdate := flag.Bool("update", false, "Update your Homebrew instance.")
brewBackup := flag.Bool("backup", false, "Backup your Homebrew instance.")
force := flag.Bool("force", false, "Forces actions such as backing up even when there are errors.")
greedy := flag.Bool("greedy", false, "Force updates to casks that have auto-update capabilities in their respective UIs.")
flag.Parse()

if *brewUpdate {
brew.Update()
brew.Update(*greedy)
return
} else if *brewBackup {
brew.Backup(*force)
Expand Down
12 changes: 9 additions & 3 deletions src/brew/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"log"
"os"
"os/exec"
"strings"

"github.com/Justintime50/alchemist/v3/src/general"
)

// Update updates your Homebrew instance
func Update() {
func Update(greedy bool) {
action := "update"
alchemistUpdateDir := general.SetupDir(action)
general.SetupLogging(alchemistUpdateDir, action)
Expand Down Expand Up @@ -40,8 +41,13 @@ func Update() {
}

fmt.Println("Alchemist is upgrading brew casks...")
upgradeCasks, upgradeCasksErr := general.RunCommand(exec.Command, "brew", []string{"upgrade", "--cask"})
if upgradeCasks != nil {
upgradeCaskCommand := []string{"upgrade", "--cask"}
if greedy {
upgradeCaskCommand = []string{"upgrade", "--cask", "--greedy"}
}
upgradeCasks, upgradeCasksErr := general.RunCommand(exec.Command, "brew", upgradeCaskCommand)
// Skip if no errors or if the cask cannot be updated due to having a manual installer
if upgradeCasks != nil || strings.Contains(fmt.Sprint(upgradeCasksErr), "installer manual") {
fmt.Println("Alchemist upgraded brew casks!")
log.Printf("brew upgrade --cask: %s", upgradeCasks)
} else {
Expand Down

0 comments on commit 4aa2bd8

Please sign in to comment.