Skip to content

Commit 03c0848

Browse files
authored
Add Interactive Version Selection (#33)
1 parent 90921a0 commit 03c0848

9 files changed

Lines changed: 208 additions & 101 deletions

File tree

README.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
[![Image Size](https://badges.cssnr.com/ghcr/size/smashedr/install-release)](https://github.com/smashedr/install-release/pkgs/container/install-release)
44
[![Go Version](https://img.shields.io/github/go-mod/go-version/smashedr/install-release?logo=go&logoColor=white&label=go)](https://github.com/smashedr/install-release/blob/master/go.mod)
55
[![Deployment Docs](https://img.shields.io/github/deployments/smashedr/install-release/docs?logo=materialformkdocs&logoColor=white&label=docs)](https://github.com/smashedr/install-release/deployments/docs)
6-
[![Deployment Preview](https://img.shields.io/github/deployments/smashedr/install-release/preview?logo=materialformkdocs&logoColor=white&label=preview)](https://github.com/smashedr/install-release/deployments/preview)
7-
[![Workflow Release](https://img.shields.io/github/actions/workflow/status/smashedr/install-release/release.yaml?logo=testcafe&logoColor=white&label=release)](https://github.com/smashedr/install-release/actions/workflows/release.yaml)
8-
[![Workflow Lint](https://img.shields.io/github/actions/workflow/status/smashedr/install-release/lint.yaml?logo=testcafe&logoColor=white&label=lint)](https://github.com/smashedr/install-release/actions/workflows/lint.yaml)
6+
[![Deployment Preview](https://img.shields.io/github/deployments/smashedr/install-release/preview?logo=labex&logoColor=white&label=preview)](https://github.com/smashedr/install-release/deployments/preview)
7+
[![Workflow Release](https://img.shields.io/github/actions/workflow/status/smashedr/install-release/release.yaml?logo=norton&logoColor=white&label=release)](https://github.com/smashedr/install-release/actions/workflows/release.yaml)
8+
[![Workflow Lint](https://img.shields.io/github/actions/workflow/status/smashedr/install-release/lint.yaml?logo=norton&logoColor=white&label=lint)](https://github.com/smashedr/install-release/actions/workflows/lint.yaml)
99
[![GitHub Last Commit](https://img.shields.io/github/last-commit/smashedr/install-release?logo=listenhub&label=updated)](https://github.com/smashedr/install-release/pulse)
10-
[![GitHub Repo Size](https://img.shields.io/github/repo-size/smashedr/install-release?logo=buffer&label=repo%20size)](https://github.com/smashedr/install-release?tab=readme-ov-file#readme)
10+
[![GitHub Repo Size](https://img.shields.io/github/repo-size/smashedr/install-release?logo=googlecloudstorage&logoColor=white&label=repo%20size)](https://github.com/smashedr/install-release?tab=readme-ov-file#readme)
1111
[![GitHub Top Language](https://img.shields.io/github/languages/top/smashedr/install-release?logo=devbox)](https://github.com/smashedr/install-release?tab=readme-ov-file#readme)
1212
[![GitHub Contributors](https://img.shields.io/github/contributors-anon/smashedr/install-release?logo=southwestairlines)](https://github.com/smashedr/install-release/graphs/contributors)
1313
[![GitHub Issues](https://img.shields.io/github/issues/smashedr/install-release?logo=codeforces&logoColor=white)](https://github.com/smashedr/install-release/issues)
@@ -31,21 +31,35 @@
3131
<img alt="Install Release" align="right" width="128" height="auto" src="https://raw.githubusercontent.com/smashedr/install-release/refs/heads/master/docs/assets/images/logo.svg"></a>
3232

3333
- [Install](#install)
34+
- [Features](#features)
3435
- [Usage](#usage)
3536
- [Development](#development)
3637
- [Support](#Support)
3738
- [Contributing](#contributing)
3839

3940
CLI to Install a GitHub Release.
4041

41-
Easily Install GitHub Release binaries with Windows, Linux and macOS Support.
42+
Easily Install GitHub Release binaries on Windows, Linux and macOS.
43+
44+
Interactively select the release version, asset, and executable name with automatically detected presets.
4245

4346
[![VHS Tape](https://cssnr.s3.amazonaws.com/install-release/demo.gif)](https://smashedr.github.io/install-release/)
4447

4548
> [!IMPORTANT]
4649
> This project is in development.
4750
> It is functional but may have bugs.
4851
52+
## Features
53+
54+
- Supports Windows, Linux and macOS
55+
- Interactively Select Options
56+
- Set Options w/ Flags or Variables
57+
- Save or Set a Custom `bin` Path
58+
- List and Remove Installed Apps
59+
- Get App Information
60+
61+
[![View Documentation](https://img.shields.io/badge/view_documentation-blue?style=for-the-badge&logo=quicklook)](https://smashedr.github.io/install-release/)
62+
4963
## Install
5064

5165
[![Latest Release](https://img.shields.io/github/v/release/smashedr/install-release?logo=github&label=latest%20release)](https://github.com/smashedr/install-release/releases)
@@ -60,7 +74,7 @@ brew install cssnr/tap/install-release
6074
#### Bash
6175

6276
```shell
63-
curl 'https://i.jpillora.com/smashedr/install-release!?as=ir' | bash
77+
curl 'https://raw.githubusercontent.com/smashedr/install-release/refs/heads/master/scripts/install.sh' | bash
6478
```
6579

6680
💾 Alternatively, you can manually [download a release](https://github.com/smashedr/install-release/releases).
@@ -87,7 +101,7 @@ docker run --rm -itv ~/bin:/out ghcr.io/smashedr/ir:latest -b /out smashedr/inst
87101

88102
_Note: Docker requires you to mount the target bin directory._
89103

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

92106
## Usage
93107

@@ -169,7 +183,7 @@ Edit the settings.
169183
ir config
170184
```
171185

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

174188
# Development
175189

@@ -225,8 +239,8 @@ For a full list of current projects visit: [https://cssnr.github.io/](https://cs
225239

226240
<a href="https://github.com/smashedr/install-release/stargazers">
227241
<picture>
228-
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=smashedr/install-release&type=date&legend=top-left&theme=dark" />
229-
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=smashedr/install-release&type=date&legend=top-left" />
230-
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=smashedr/install-release&type=date&legend=top-left" />
242+
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=smashedr/install-release&type=date&legend=bottom-right&theme=dark" />
243+
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=smashedr/install-release&type=date&legend=bottom-right" />
244+
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=smashedr/install-release&type=date&legend=bottom-right" />
231245
</picture>
232246
</a>

Taskfile.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ tasks:
2828
- task: pslint
2929

3030
pslint:
31+
desc: Invoke-ScriptAnalyzer does NOT exit with error!
3132
platforms: [windows]
3233
cmd: powershell -Command "Invoke-ScriptAnalyzer -Path scripts -Recurse"
3334

assets/main.tape

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ Type "ir smashedr/bup"
33
Sleep 0.5s
44
Enter
55

6+
# select version
7+
Wait / [0-9]\.[0-9]/
8+
Sleep 1.5s
9+
Down
10+
Sleep 0.2s
11+
Down
12+
Sleep 0.5s
13+
Up
14+
Sleep 0.2s
15+
Up
16+
Sleep 0.5s
17+
Enter
18+
# select asset
619
Wait / bup_/
720
Sleep 1.5s
821
Up
@@ -14,6 +27,7 @@ Sleep 0.2s
1427
Down
1528
Sleep 0.5s
1629
Enter
30+
# set name
1731
Wait /\> /
1832
Sleep 1s
1933
Backspace

cmd/info.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ var infoCmd = &cobra.Command{
3131
}
3232
log.Info("Repository", "owner", owner, "repo", repo, "tag", tag)
3333
client := getClient()
34-
release, err := getRelease(client, owner, repo, tag, preRelease)
34+
release, err := getRelease(client, owner, repo, tag, preRelease, true)
3535
if err != nil {
3636
log.Fatalf("Error getting release: %v", err)
3737
}
38+
if release == nil {
39+
log.Fatalf("No release found")
40+
}
3841
if verbose >= 3 {
3942
log.Debugf("%v", release)
4043
}

cmd/install.go

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ func runInstall(cmd *cobra.Command, args []string) error { // NOSONAR
6666

6767
client := getClient()
6868

69-
release, err := getRelease(client, owner, repo, tag, preRelease)
69+
release, err := getRelease(client, owner, repo, tag, preRelease, skipPrompts)
7070
if err != nil {
7171
return fmt.Errorf("get release error: %w", err)
7272
}
73+
if release == nil {
74+
return fmt.Errorf("no release found")
75+
}
7376
if verbose >= 3 {
7477
log.Debugf("release: %v", release)
7578
}
@@ -392,19 +395,22 @@ func getClient() *github.Client {
392395
return github.NewClient(httpClient)
393396
}
394397

395-
func getRelease(client *github.Client, owner, repo, tag string, pre bool) (*github.RepositoryRelease, error) {
398+
func getRelease(client *github.Client, owner, repo, tag string, pre, skip bool) (*github.RepositoryRelease, error) {
396399
ctx := context.Background()
397400
var release *github.RepositoryRelease
398401
var err error
399402
if tag != "" {
400403
log.Debugf("client.Repositories.GetReleaseByTag: %v", tag)
401404
release, _, err = client.Repositories.GetReleaseByTag(ctx, owner, repo, tag)
402405
} else if pre {
403-
log.Debugf("GetLatestRelease - Including Pre-Releases")
406+
log.Debugf("GetLatestRelease")
404407
release, err = getLatestRelease(client, owner, repo)
405-
} else {
408+
} else if skip {
406409
log.Debugf("client.Repositories.GetLatestRelease")
407410
release, _, err = client.Repositories.GetLatestRelease(ctx, owner, repo)
411+
} else {
412+
log.Debugf("chooseRelease")
413+
release, err = chooseRelease(client, owner, repo, 30)
408414
}
409415
if err != nil {
410416
return nil, fmt.Errorf("get release error: %w", err)
@@ -413,16 +419,52 @@ func getRelease(client *github.Client, owner, repo, tag string, pre bool) (*gith
413419
}
414420

415421
func getLatestRelease(client *github.Client, owner, repo string) (*github.RepositoryRelease, error) {
422+
releases, err := getReleases(client, owner, repo, 1)
423+
if err != nil {
424+
return nil, err
425+
}
426+
if len(releases) == 0 {
427+
return nil, nil
428+
}
429+
return releases[0], nil
430+
}
431+
432+
func getReleases(client *github.Client, owner, repo string, number int) ([]*github.RepositoryRelease, error) {
416433
ctx := context.Background()
417-
releases, _, err := client.Repositories.ListReleases(ctx, owner, repo, &github.ListOptions{PerPage: 1})
434+
releases, _, err := client.Repositories.ListReleases(ctx, owner, repo, &github.ListOptions{PerPage: number})
418435
if err != nil {
419436
return nil, err
420437
}
421-
if len(releases) > 0 {
422-
return releases[0], nil
438+
return releases, nil
439+
}
440+
441+
func chooseRelease(client *github.Client, owner, repo string, number int) (*github.RepositoryRelease, error) {
442+
releases, err := getReleases(client, owner, repo, number)
443+
if err != nil {
444+
return nil, fmt.Errorf("error getting releases: %w", err)
445+
}
446+
447+
log.Debugf("releases: %v", len(releases))
448+
var result1 int
449+
options := make([]huh.Option[int], len(releases))
450+
for i, release := range releases {
451+
options[i] = huh.NewOption(release.GetTagName(), i)
423452
}
424-
// TODO: Consider returning an error here...
425-
return nil, nil
453+
form := huh.NewSelect[int]().
454+
Title("Select a version:").
455+
Options(options...).
456+
Value(&result1)
457+
458+
err = form.Run()
459+
if err != nil {
460+
return nil, fmt.Errorf("prompt failed: %w", err)
461+
}
462+
log.Debugf("result1: %v", result1)
463+
464+
chosen := releases[result1]
465+
log.Debugf("release: %v", chosen)
466+
log.Debugf("tag: %v", chosen.GetTagName())
467+
return chosen, nil
426468
}
427469

428470
func ensureWinExt(destName string) string {

docs/index.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ icon: lucide/rocket
1111
[![Image Size](https://badges.cssnr.com/ghcr/size/smashedr/install-release)](https://github.com/smashedr/install-release/pkgs/container/install-release)
1212
[![Go Version](https://img.shields.io/github/go-mod/go-version/smashedr/install-release?logo=go&logoColor=white&label=go)](https://github.com/smashedr/install-release/blob/master/go.mod)
1313
[![GitHub Last Commit](https://img.shields.io/github/last-commit/smashedr/install-release?logo=listenhub&label=updated)](https://github.com/smashedr/install-release/pulse)
14-
[![GitHub Repo Size](https://img.shields.io/github/repo-size/smashedr/install-release?logo=buffer&label=repo%20size)](https://github.com/smashedr/install-release?tab=readme-ov-file#readme)
14+
[![GitHub Repo Size](https://img.shields.io/github/repo-size/smashedr/install-release?logo=googlecloudstorage&logoColor=white&label=repo%20size)](https://github.com/smashedr/install-release?tab=readme-ov-file#readme)
1515
[![GitHub Top Language](https://img.shields.io/github/languages/top/smashedr/install-release?logo=devbox)](https://github.com/smashedr/install-release?tab=readme-ov-file#readme)
1616
[![GitHub Contributors](https://img.shields.io/github/contributors-anon/smashedr/install-release?logo=southwestairlines)](https://github.com/smashedr/install-release/graphs/contributors)
1717
[![GitHub Issues](https://img.shields.io/github/issues/smashedr/install-release?logo=codeforces&logoColor=white)](https://github.com/smashedr/install-release/issues)
18-
[![GitHub Discussions](https://img.shields.io/github/discussions/smashedr/install-release?logo=theconversation&logoColor=white)](https://github.com/smashedr/install-release/discussions)
18+
[![GitHub Discussions](https://img.shields.io/github/discussions/smashedr/install-release?logo=theconversation)](https://github.com/smashedr/install-release/discussions)
1919
[![GitHub Forks](https://img.shields.io/github/forks/smashedr/install-release?style=flat&logo=forgejo&logoColor=white)](https://github.com/smashedr/install-release/forks)
2020
[![GitHub Repo Stars](https://img.shields.io/github/stars/smashedr/install-release?style=flat&logo=gleam&logoColor=white)](https://github.com/smashedr/install-release/stargazers)
2121
[![GitHub Org Stars](https://img.shields.io/github/stars/cssnr?style=flat&logo=apachespark&logoColor=white&label=org%20stars)](https://cssnr.github.io/)
@@ -24,7 +24,9 @@ icon: lucide/rocket
2424

2525
CLI to Install a GitHub Release.
2626

27-
Easily Install GitHub Release binaries with Windows, Linux and macOS Support.
27+
Easily Install GitHub Release binaries on Windows, Linux and macOS.
28+
29+
Interactively select the release version, asset, and executable name with automatically detected presets.
2830

2931
--8<-- "docs/snippets/install.md"
3032

@@ -38,12 +40,12 @@ If you run into any issues or have any questions, [support](support.md) is avail
3840

3941
## :lucide-sparkles: Features
4042

41-
- Supports Windows
42-
- Custom `bin` Path
43-
- Automatic Release Detection
44-
- Select Asset and Name Interactively
45-
- Set Asset and Name Programmatically
43+
- Supports Windows, Linux and macOS
44+
- Interactively Select Options
45+
- Set Options w/ Flags or Variables
46+
- Save or Set a Custom `bin` Path
4647
- List and Remove Installed Apps
48+
- Get App Information
4749

4850
## :lucide-plane-takeoff: Install
4951

docs/snippets/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
=== ":lucide-terminal-square: bash"
88

99
```shell
10-
curl 'https://i.jpillora.com/smashedr/install-release!?as=ir' | bash # (1)!
10+
curl 'https://raw.githubusercontent.com/smashedr/install-release/refs/heads/master/scripts/install.sh' | bash # (1)!
1111
```
1212

1313
1. Alternatively, you can manually [download a release](https://github.com/smashedr/install-release/releases).

docs/support.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ From here you can contact me directly, `Shane@111150265075298304`.
4848

4949
More information available at: [https://cssnr.com/](https://cssnr.com/)
5050

51-
[![Image title](https://cdn.prod.website-files.com/5c14e387dab576fe667689cf/670f5a01c01ea9191809398c_support_me_on_kofi_blue.png){ width="360" }](https://ko-fi.com/cssnr)
51+
[![Support on Ko-fi](https://cdn.prod.website-files.com/5c14e387dab576fe667689cf/670f5a01c01ea9191809398c_support_me_on_kofi_blue.png){ width="360" }](https://ko-fi.com/cssnr)
52+
53+
<a href="https://github.com/smashedr/install-release/stargazers">
54+
<picture>
55+
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=smashedr/install-release&type=date&legend=bottom-right&theme=dark" />
56+
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=smashedr/install-release&type=date&legend=bottom-right" />
57+
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=smashedr/install-release&type=date&legend=bottom-right" />
58+
</picture>
59+
</a>

0 commit comments

Comments
 (0)