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
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
- [Install](#install)
- [Features](#features)
- [Usage](#usage)
- [Support](#support)
- [Development](#development)
- [Support](#Support)
- [Contributing](#contributing)

CLI to Install a GitHub Release.
Expand Down Expand Up @@ -202,6 +202,20 @@ ir config

[![View Documentation](https://img.shields.io/badge/view_documentation-blue?style=for-the-badge&logo=quicklook)](https://smashedr.github.io/install-release/)

## Support

If you run into any issues or need help getting started, please do one of the following:

- Report an Issue: <https://github.com/smashedr/install-release/issues>
- Q&A Discussion: <https://github.com/smashedr/install-release/discussions/categories/q-a>
- Request a Feature: <https://github.com/smashedr/install-release/issues/new?template=1-feature.yaml>
- Chat with us on Discord: <https://discord.gg/wXy6m2X8wY>

[![Features](https://img.shields.io/badge/features-brightgreen?style=for-the-badge&logo=rocket&logoColor=white)](https://github.com/smashedr/install-release/issues/new?template=1-feature.yaml)
[![Issues](https://img.shields.io/badge/issues-red?style=for-the-badge&logo=southwestairlines&logoColor=white)](https://github.com/smashedr/install-release/issues)
[![Discussions](https://img.shields.io/badge/discussions-blue?style=for-the-badge&logo=livechat&logoColor=white)](https://github.com/smashedr/install-release/discussions)
[![Discord](https://img.shields.io/badge/discord-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/wXy6m2X8wY)

# Development

Go: <https://go.dev/doc/install>
Expand Down Expand Up @@ -229,20 +243,6 @@ Inno Setup: <https://jrsoftware.org/isdl.php>
task inno
```

# Support

If you run into any issues or need help getting started, please do one of the following:

- Report an Issue: <https://github.com/smashedr/install-release/issues>
- Q&A Discussion: <https://github.com/smashedr/install-release/discussions/categories/q-a>
- Request a Feature: <https://github.com/smashedr/install-release/issues/new?template=1-feature.yaml>
- Chat with us on Discord: <https://discord.gg/wXy6m2X8wY>

[![Features](https://img.shields.io/badge/features-brightgreen?style=for-the-badge&logo=rocket&logoColor=white)](https://github.com/smashedr/install-release/issues/new?template=1-feature.yaml)
[![Issues](https://img.shields.io/badge/issues-red?style=for-the-badge&logo=southwestairlines&logoColor=white)](https://github.com/smashedr/install-release/issues)
[![Discussions](https://img.shields.io/badge/discussions-blue?style=for-the-badge&logo=livechat&logoColor=white)](https://github.com/smashedr/install-release/discussions)
[![Discord](https://img.shields.io/badge/discord-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/wXy6m2X8wY)

# Contributing

If you would like to submit a PR, please review the [CONTRIBUTING.md](#contributing-ov-file).
Expand Down
196 changes: 114 additions & 82 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"runtime"
"strings"
Expand All @@ -44,92 +45,19 @@ func runInstall(cmd *cobra.Command, args []string) error { // NOSONAR
skipPrompts := viper.GetBool("yes")
assetName := viper.GetString("asset")
destName := viper.GetString("name")
assetUrl := viper.GetString("url")
preRelease, _ := cmd.Flags().GetBool("pre")
log.Info("Flags:", "skipPrompts", skipPrompts, "assetName", assetName, "destName", destName, "preRelease", preRelease)
log.Info("Flags:", "skipPrompts", skipPrompts, "assetName", assetName, "destName", destName, "preRelease", preRelease, "assetUrl", assetUrl)

if len(args) < 1 {
_ = cmd.Help()
return fmt.Errorf("repository must be in format: owner/repo")
}

repo, err := parseRepository(args)
if err != nil {
log.Debugf("parseRepository err: %v", err)
_ = cmd.Help()
return err
}
log.Info("Repository", "repo", repo)

log.Info("runtime", "GOOS", runtime.GOOS, "GOARCH", runtime.GOARCH)

tagDisplay := repo.Tag
if repo.Tag == "" {
if preRelease {
tagDisplay = "pre-release"
} else {
tagDisplay = "latest"
}
}
styles.PrintKV("Repository", fmt.Sprintf("%s/%s:%s", repo.Owner, repo.Name, tagDisplay))

client := getClient()

release, err := getRelease(client, repo, preRelease, skipPrompts)
if err != nil {
return fmt.Errorf("get release error: %w", err)
}
if release == nil {
return fmt.Errorf("no release found")
}
if verbose >= 3 {
log.Debugf("release: %v", release)
}

//styles.PrintKV("Version", fmt.Sprintf("%s (%s)", release.GetTagName(), release.GetName()))
renderReleaseTable(release)

// Asset
var asset *github.ReleaseAsset
var result int
var rc io.ReadCloser
var rcName string
var err error

if assetName != "" {
result = findAssetByName(release.Assets, assetName)
if assetUrl != "" {
rc, rcName, err = downloadAssetURL(assetUrl)
} else {
result = findAssetByPlatform(release.Assets, runtime.GOOS, runtime.GOARCH)
rc, rcName, err = processRepository(cmd, args, preRelease, skipPrompts, assetName)
}
log.Debugf("result: %v", result)

if result < 0 || !skipPrompts {
options := make([]huh.Option[int], len(release.Assets))
for i, asset := range release.Assets {
options[i] = huh.NewOption(asset.GetName(), i)
}
form := huh.NewSelect[int]().
Title("Select a release asset:").
Options(options...).
Value(&result)

err = form.Run()
if err != nil {
return fmt.Errorf("prompt failed: %w", err)
}
}

log.Debugf("result: %v", result)
asset = release.Assets[result]
log.Debugf("asset: %v", asset)

if asset == nil {
return fmt.Errorf("no asset selected")
}

log.Infof("id: %v", asset.GetID())
log.Infof("url: %v", asset.GetBrowserDownloadURL())
styles.PrintKV("Asset Name", asset.GetName())

rc, _, err := client.Repositories.DownloadReleaseAsset(
context.Background(), repo.Owner, repo.Name, asset.GetID(), http.DefaultClient,
)
if err != nil {
return err
}
Expand Down Expand Up @@ -189,7 +117,7 @@ func runInstall(cmd *cobra.Command, args []string) error { // NOSONAR
binaryFilePath = tmpFile.Name()
log.Debugf("2 binaryFilePath: %v", binaryFilePath)
if destName == "" {
destName = asset.GetName()
destName = rcName
}
}
log.Infof("binaryFilePath: %v", binaryFilePath)
Expand Down Expand Up @@ -266,6 +194,110 @@ func runInstall(cmd *cobra.Command, args []string) error { // NOSONAR
return nil
}

func processRepository(cmd *cobra.Command, args []string, preRelease bool, skipPrompts bool, assetName string) (io.ReadCloser, string, error) { // NOSONAR
if len(args) < 1 {
_ = cmd.Help()
return nil, "", fmt.Errorf("repository must be in format: owner/repo")
}

repo, err := parseRepository(args)
if err != nil {
log.Debugf("parseRepository err: %v", err)
_ = cmd.Help()
return nil, "", err
}
log.Info("Repository", "repo", repo)

log.Info("runtime", "GOOS", runtime.GOOS, "GOARCH", runtime.GOARCH)

tagDisplay := repo.Tag
if repo.Tag == "" {
if preRelease {
tagDisplay = "pre-release"
} else {
tagDisplay = "latest"
}
}
styles.PrintKV("Repository", fmt.Sprintf("%s/%s:%s", repo.Owner, repo.Name, tagDisplay))

client := getClient()

release, err := getRelease(client, repo, preRelease, skipPrompts)
if err != nil {
return nil, "", fmt.Errorf("get release error: %w", err)
}
if release == nil {
return nil, "", fmt.Errorf("no release found")
}
if verbose >= 3 {
log.Debugf("release: %v", release)
}

//styles.PrintKV("Version", fmt.Sprintf("%s (%s)", release.GetTagName(), release.GetName()))
renderReleaseTable(release)

// Asset
var asset *github.ReleaseAsset
var result int

if assetName != "" {
result = findAssetByName(release.Assets, assetName)
} else {
result = findAssetByPlatform(release.Assets, runtime.GOOS, runtime.GOARCH)
}
log.Debugf("result: %v", result)

if result < 0 || !skipPrompts {
options := make([]huh.Option[int], len(release.Assets))
for i, asset := range release.Assets {
options[i] = huh.NewOption(asset.GetName(), i)
}
form := huh.NewSelect[int]().
Title("Select a release asset:").
Options(options...).
Value(&result)

err = form.Run()
if err != nil {
return nil, "", fmt.Errorf("prompt failed: %w", err)
}
}

log.Debugf("result: %v", result)
asset = release.Assets[result]
log.Debugf("asset: %v", asset)

if asset == nil {
return nil, "", fmt.Errorf("no asset selected")
}

log.Infof("id: %v", asset.GetID())
log.Infof("url: %v", asset.GetBrowserDownloadURL())
styles.PrintKV("Asset Name", asset.GetName())

rc, _, err := client.Repositories.DownloadReleaseAsset(
context.Background(), repo.Owner, repo.Name, asset.GetID(), http.DefaultClient,
)
if err != nil {
return nil, "", err
}
return rc, asset.GetName(), nil
}

func downloadAssetURL(assetURL string) (io.ReadCloser, string, error) {
resp, err := http.DefaultClient.Get(assetURL)
if err != nil {
return nil, "", fmt.Errorf("%s for url: %s", err, assetURL)
}

if resp.StatusCode != http.StatusOK {
_ = resp.Body.Close()
return nil, "", fmt.Errorf("%d: %s for url: %s", resp.StatusCode, resp.Status, assetURL)
}
name := strings.TrimSuffix(path.Base(assetURL), path.Ext(assetURL))
return resp.Body, name, nil
}

func extractArchive(format archives.Format, stream io.Reader, tmpDir string) (string, error) { // NOSONAR
ex, ok := format.(archives.Extractor)
if !ok {
Expand Down
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ func init() {
_ = viper.BindPFlag("name", rootCmd.PersistentFlags().Lookup("name"))
rootCmd.PersistentFlags().BoolP("pre", "p", false, "include pre-releases")

rootCmd.PersistentFlags().StringP("url", "u", "", "url of asset to download")
_ = viper.BindPFlag("url", rootCmd.PersistentFlags().Lookup("url"))

rootCmd.PersistentFlags().BoolP("yes", "y", false, "answer yes to prompts")
_ = viper.BindPFlag("yes", rootCmd.PersistentFlags().Lookup("yes"))

Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.25.6

require (
github.com/bartventer/httpcache v0.12.0
github.com/charmbracelet/huh v0.8.0
github.com/charmbracelet/huh v1.0.0
github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834
github.com/charmbracelet/log v0.4.2
github.com/charmbracelet/log v1.0.0
github.com/confluentinc/go-editor v0.11.0
github.com/dustin/go-humanize v1.0.1
github.com/google/go-github/v58 v58.0.0
Expand All @@ -26,7 +26,7 @@ require (
github.com/catppuccin/go v0.3.0 // indirect
github.com/charmbracelet/bubbles v1.0.0 // indirect
github.com/charmbracelet/bubbletea v1.3.10 // indirect
github.com/charmbracelet/colorprofile v0.4.2 // indirect
github.com/charmbracelet/colorprofile v0.4.3 // indirect
github.com/charmbracelet/x/ansi v0.11.6 // indirect
github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
github.com/charmbracelet/x/exp/strings v0.1.0 // indirect
Expand All @@ -46,16 +46,16 @@ require (
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.21 // indirect
github.com/mikelolasagasti/xz v1.0.1 // indirect
github.com/minio/minlz v1.0.1 // indirect
github.com/minio/minlz v1.1.0 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.16.0 // indirect
github.com/nwaples/rardecode/v2 v2.2.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pierrec/lz4/v4 v4.1.25 // indirect
github.com/pierrec/lz4/v4 v4.1.26 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.12.0 // indirect
github.com/sorairolake/lzip-go v0.3.8 // indirect
Expand All @@ -68,7 +68,7 @@ require (
go.yaml.in/yaml/v3 v3.0.4 // indirect
go4.org v0.0.0-20260112195520-a5071408f32f // indirect
golang.org/x/exp v0.0.0-20260218203240-3dfff04db8fa // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
golang.org/x/sys v0.42.0 // indirect
golang.org/x/text v0.35.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
Loading
Loading