Show brew upgrade
when installed with Homebrew (#2519)
Show `brew upgrade pulumi` as the upgrade message when the currently running pulumi executable is on macOS and running from the brew install directory.
This commit is contained in:
parent
62b6f1c3b2
commit
7784c94c88
|
@ -2,6 +2,9 @@
|
|||
|
||||
### Improvements
|
||||
|
||||
- Show `brew upgrade pulumi` as the upgrade message when the currently running `pulumi` executable
|
||||
is running on macOS from the brew install directory.
|
||||
|
||||
## 0.17.1 (Released March 6, 2019)
|
||||
|
||||
### Improvements
|
||||
|
|
|
@ -16,6 +16,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -324,6 +325,14 @@ func getUpgradeCommand() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
isBrew, err := isBrewInstall(exe)
|
||||
if err != nil {
|
||||
glog.V(3).Infof("error determining if the running executable was installed with brew: %s", err)
|
||||
}
|
||||
if isBrew {
|
||||
return "$ brew upgrade pulumi"
|
||||
}
|
||||
|
||||
if filepath.Dir(exe) != filepath.Join(curUser.HomeDir, ".pulumi", "bin") {
|
||||
return ""
|
||||
}
|
||||
|
@ -342,6 +351,47 @@ func getUpgradeCommand() string {
|
|||
`((New-Object System.Net.WebClient).DownloadString('https://get.pulumi.com/install.ps1'))"`
|
||||
}
|
||||
|
||||
// isBrewInstall returns true if the current running executable is running on macOS and was installed with brew.
|
||||
func isBrewInstall(exe string) (bool, error) {
|
||||
if runtime.GOOS != "darwin" {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
exePath, err := filepath.EvalSymlinks(exe)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
brewBin, err := exec.LookPath("brew")
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
brewPrefixCmd := exec.Command(brewBin, "--prefix", "pulumi")
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
brewPrefixCmd.Stdout = &stdout
|
||||
if err = brewPrefixCmd.Run(); err != nil {
|
||||
if ee, ok := err.(*exec.ExitError); ok {
|
||||
ee.Stderr = stderr.Bytes()
|
||||
}
|
||||
return false, errors.Wrapf(err, "'brew --prefix pulumi' failed")
|
||||
}
|
||||
|
||||
brewPrefixCmdOutput := strings.TrimSpace(stdout.String())
|
||||
if brewPrefixCmdOutput == "" {
|
||||
return false, errors.New("trimmed output from 'brew --prefix pulumi' is empty")
|
||||
}
|
||||
|
||||
brewPrefixPath, err := filepath.EvalSymlinks(brewPrefixCmdOutput)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
brewPrefixExePath := filepath.Join(brewPrefixPath, "bin", "pulumi")
|
||||
return exePath == brewPrefixExePath, nil
|
||||
}
|
||||
|
||||
func isDevVersion(s semver.Version) bool {
|
||||
if len(s.Pre) == 0 {
|
||||
return false
|
||||
|
|
Loading…
Reference in a new issue