Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: Add av upgrade #459

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
60 changes: 45 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,47 +112,77 @@ $ av stack sync

```

# Installation
# Installation & Upgrade

`av` is available for macOS and Linux. In order to interact with GitHub, `av`
uses the GitHub API token. If you have [GitHub CLI](https://cli.github.com/)
installed, `av` will use the token automatically from the GitHub CLI. It is
recommended to install both.
`av` is available for macOS and Linux. You can install and upgrade it using the following methods:

## macOS

Install via Homebrew:
```sh
brew install gh aviator-co/tap/av
```

Upgrade:
```sh
brew upgrade av
```

## Arch Linux (AUR)

Published as [`av-cli-bin`](https://aur.archlinux.org/packages/av-cli-bin) in
AUR.
Install via AUR (published as [`av-cli-bin`](https://aur.archlinux.org/packages/av-cli-bin)):
```sh
yay -S av-cli-bin
```

Upgrade:
```sh
yay av-cli
yay -S av-cli-bin
```

## Debian/Ubuntu

Download the `.deb` file from the [releases page](https://github.com/aviator-co/av/releases).

Download the `.deb` file from the [releases page](https://github.com/aviator-co/av/releases):
```sh
apt install ./av_$VERSION_linux_$ARCH.deb
# Install
sudo dpkg -i ./av_$VERSION_linux_$ARCH.deb

# Upgrade
av upgrade # or use dpkg -i with the new version
```

## RPM-based systems

Download the `.rpm` file from the [releases page](https://github.com/aviator-co/av/releases).
Download the `.rpm` file from the [releases page](https://github.com/aviator-co/av/releases):
```sh
# Install
sudo rpm -i ./av_$VERSION_linux_$ARCH.rpm

# Upgrade
av upgrade # or use rpm -U with the new version
```

## Binary installation

1. Download the binary for your system from the [releases page](https://github.com/aviator-co/av/releases)
2. Extract and install the binary:
```sh
rpm -i ./av_$VERSION_linux_$ARCH.rpm
# Download and install
curl -L -o av.tar.gz "https://github.com/aviator-co/av/releases/latest/download/av_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m).tar.gz"
sudo tar xzf av.tar.gz -C /usr/local/bin

# Upgrade
av upgrade # or repeat the installation steps with the new version
```

## Binary download
## Automatic upgrades

Once installed, you can upgrade `av` using the built-in upgrade command:
```sh
av upgrade
```

Download the binary from the [releases page](https://github.com/aviator-co/av/releases).
This command will automatically detect how `av` was installed and perform the appropriate upgrade.

# Setup

Expand Down
10 changes: 8 additions & 2 deletions cmd/av/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func init() {
stackCmd,
versionCmd,
authCmd,
upgradeCmd,
)
}

Expand All @@ -109,7 +110,12 @@ func main() {
colors.SetupBackgroundColorTypeFromEnv()
err := rootCmd.Execute()
logrus.WithField("duration", time.Since(startTime)).Debug("command exited")
checkCliVersion()

// Skip version check if running the upgrade command
if len(os.Args) > 1 && os.Args[1] != "upgrade" {
checkCliVersion()
}

var exitSilently actions.ErrExitSilently
if errors.As(err, &exitSilently) {
os.Exit(exitSilently.ExitCode)
Expand Down Expand Up @@ -157,7 +163,7 @@ func checkCliVersion() {
c.Sprint(" => "),
color.GreenString(latest),
"\n",
c.Sprint(">> https://docs.aviator.co/reference/aviator-cli/installation#upgrade\n"),
c.Sprint(">> Run `av upgrade` or see https://docs.aviator.co/reference/aviator-cli/installation#upgrade for other methods\n"),
)
}
}
Expand Down
29 changes: 29 additions & 0 deletions cmd/av/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"fmt"
"os"
"runtime"

"github.com/aviator-co/av/internal/actions"
"github.com/aviator-co/av/internal/utils/colors"
"github.com/spf13/cobra"
)

var upgradeCmd = &cobra.Command{
Use: "upgrade",
Short: "Upgrade the av CLI to the latest version",
Long: `Upgrade the av CLI to the latest version.

This command checks for the latest release and updates the CLI accordingly.
If the CLI was installed via a package manager (e.g., Homebrew, AUR), it will
suggest using the package manager to perform the upgrade.`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := actions.UpgradeCLI(runtime.GOOS, runtime.GOARCH); err != nil {
fmt.Fprintln(os.Stderr, colors.Failure("Failed to upgrade av CLI:", err))
return actions.ErrExitSilently{ExitCode: 1}
}
fmt.Fprintln(os.Stdout, colors.Success("Successfully upgraded av CLI to the latest version."))
return nil
},
}
Loading