mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-25 19:14:50 -08:00
refactor(upgrade): move download inline
This commit is contained in:
parent
ddd2d154df
commit
7c7bd14a45
|
@ -1,10 +1,7 @@
|
|||
package upgrade
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/charmbracelet/bubbles/spinner"
|
||||
|
@ -12,7 +9,6 @@ import (
|
|||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/build"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/platform/net"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -98,6 +94,7 @@ func (m *model) View() string {
|
|||
|
||||
var message string
|
||||
m.spinner.Spinner = spinner.Dot
|
||||
|
||||
switch m.state {
|
||||
case validating:
|
||||
message = "Validating current installation"
|
||||
|
@ -128,23 +125,3 @@ func Run(env platform.Environment) {
|
|||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func downloadAsset(asset string) (io.ReadCloser, error) {
|
||||
url := fmt.Sprintf("https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/%s", asset)
|
||||
|
||||
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := net.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("failed to download installer: %s", url)
|
||||
}
|
||||
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
|
|
@ -2,13 +2,16 @@ package upgrade
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/platform"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/platform/net"
|
||||
)
|
||||
|
||||
func install() error {
|
||||
|
@ -28,14 +31,25 @@ func install() error {
|
|||
|
||||
setState(downloading)
|
||||
|
||||
data, err := downloadAsset(asset)
|
||||
url := fmt.Sprintf("https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/%s", asset)
|
||||
|
||||
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer data.Close()
|
||||
resp, err := net.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newBytes, err := io.ReadAll(data)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("failed to download installer: %s", url)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
newBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue