Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* `version check` command to check if a newer CLI version is available.
* `version update` command to download and install the latest CLI version from GitHub releases.
* `build start` command now accepts optional `--ref` flag to build from specific git references (branches, tags, or commit hashes).
* `modify app` command to update some parameters of application/pipeline stacks.

Expand Down
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func printUpdateMessage(newRelease *version.ReleaseInfo) {
appPath, err := exec.LookPath(os.Args[0])
checkErr(err)

isHomebrew := isUnderHomebrew(appPath)
isHomebrew := IsUnderHomebrew(appPath)

fmt.Fprintf(os.Stderr, "\n\n%s %s → %s\n",
aurora.Yellow("A new release of apppack is available:"),
Expand Down Expand Up @@ -184,8 +184,8 @@ func confirmAction(message, text string) {
}
}

// Check whether the apppack binary was found under the Homebrew prefix
func isUnderHomebrew(apppackBinary string) bool {
// IsUnderHomebrew checks whether the apppack binary was found under the Homebrew prefix.
func IsUnderHomebrew(apppackBinary string) bool {
brewExe, err := safeexec.LookPath("brew")
if err != nil {
return false
Expand Down
86 changes: 86 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ limitations under the License.
package cmd

import (
"context"
"fmt"
"net/http"
"os"
"strings"

"github.com/apppackio/apppack/selfupdate"
"github.com/apppackio/apppack/ui"
"github.com/apppackio/apppack/version"
"github.com/cli/safeexec"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
)

var forceUpdate bool

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Expand All @@ -36,6 +46,82 @@ var versionCmd = &cobra.Command{
},
}

// versionCheckCmd checks if a newer version is available
var versionCheckCmd = &cobra.Command{
Use: "check",
Short: "check if a newer version is available",
DisableFlagsInUseLine: true,
Run: func(_ *cobra.Command, _ []string) {
ctx := context.Background()
ui.StartSpinner()
ui.Spinner.Suffix = " checking for updates..."

release, err := version.GetLatestReleaseInfo(ctx, http.DefaultClient, repo)
checkErr(err)

ui.Spinner.Stop()

if version.VersionGreaterThan(release.Version, version.Version) {
fmt.Printf("%s %s → %s\n",
aurora.Yellow("Update available:"),
aurora.Cyan(strings.TrimPrefix(version.Version, "v")),
aurora.Cyan(strings.TrimPrefix(release.Version, "v")),
)
fmt.Printf("Run %s to update\n", aurora.White("apppack version update"))
} else {
printSuccess(fmt.Sprintf("Already up to date (version %s)", strings.TrimPrefix(version.Version, "v")))
}
},
}

// versionUpdateCmd updates apppack to the latest version
var versionUpdateCmd = &cobra.Command{
Use: "update",
Short: "update apppack to the latest version",
Long: "Downloads and installs the latest version of apppack from GitHub releases.",
DisableFlagsInUseLine: true,
Run: func(_ *cobra.Command, _ []string) {
ctx := context.Background()

// Get current binary path
appPath, err := safeexec.LookPath(os.Args[0])
checkErr(err)

// Block Homebrew installs
if IsUnderHomebrew(appPath) {
printWarning("AppPack was installed via Homebrew")
fmt.Printf("To update, run: %s\n", aurora.White("brew upgrade apppack"))

return
}

ui.StartSpinner()
ui.Spinner.Suffix = " checking for updates..."

release, err := version.GetLatestReleaseInfo(ctx, http.DefaultClient, repo)
checkErr(err)

// Check if update is needed
if !forceUpdate && !version.VersionGreaterThan(release.Version, version.Version) {
ui.Spinner.Stop()
printSuccess(fmt.Sprintf("Already up to date (version %s)", strings.TrimPrefix(version.Version, "v")))

return
}

ui.Spinner.Suffix = fmt.Sprintf(" downloading %s...", release.Version)

err = selfupdate.Update(ctx, http.DefaultClient, release, appPath)
checkErr(err)

ui.Spinner.Stop()
printSuccess(fmt.Sprintf("Updated to version %s", strings.TrimPrefix(release.Version, "v")))
},
}

func init() {
rootCmd.AddCommand(versionCmd)
versionCmd.AddCommand(versionCheckCmd)
versionCmd.AddCommand(versionUpdateCmd)
versionUpdateCmd.Flags().BoolVarP(&forceUpdate, "force", "f", false, "force update even if already on latest version")
}
Loading