Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Use cache by default on updates
  Update cache
  Update cache
  • Loading branch information
leucos committed Dec 26, 2020
2 parents 8a8185f + f55cf46 commit 6b03012
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 32 deletions.
33 changes: 14 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ The last binary you'll ever install.
- [Supported "distributions"](#supported-distributions)
- [Usage](#usage)
- [Updating available distributions versions](#updating-available-distributions-versions)
- [Updating versions from generated cache](#updating-versions-from-generated-cache)
- [Updating versions using a token](#updating-versions-using-a-token)
- [Update available distributions](#update-available-distributions)
- [Examples](#examples)
Expand Down Expand Up @@ -266,30 +265,23 @@ to update the version list (usually located in `$XDG_CONFIG/cache.json` or

This is done automatically when invoking `binenv update`.

Without arguments, it will check for available versions for _all_ distributions
(watch out for Github API rate limits, [but see below](#updating-versions-from-generated-cache)).
Without arguments, it will fetch the cache from this repo. This cache is
generated automatically daily.

Using the `-f` argument, `binenv` will retrieve available versions for _all_
distributions (watch out for Github API rate limits, [but see
below](#updating-versions-from-generated-cache)).

With a distribution passed as an argument (e.g. `binenv update kubectl`), it
will only update installable versions for `kubectl`.

Note that Github enforces rate limits (e.g. 60 unauthenticated API requests per
hours). So you should update all distributions (e.g. `binenv update`) with
caution.

`binenv` will stop updating distributions when you only have 4 unauthenticated
API requests left so you can [update from generated cache](#updating-versions-from-generated-cache).
hours). So you should update all distributions (e.g. `binenv update -f`) with
caution. `binenv` will stop updating distributions when you only have 4
unauthenticated API requests left.

[GitHub tokens](#updating-versions-using-a-token) are also supported to avoid
being rate-limited.

#### Updating versions from generated cache

To avoid hitting the GitHub unauthenticated rate limit, `binenv` can fetch a
nightly generated versions cache from github using the `--cache` flag:

```bash
binenv update --cache # or -c
```
being rate-limited and fetch releases from their respective sources.

#### Updating versions using a token

Expand Down Expand Up @@ -329,7 +321,10 @@ binenv update --all # or -a

#### Examples

- `binenv update`: update available versions for all distributions
- `binenv update`: update available versions for all distributions from github
cache
- `binenv update -f`: update available versions for all distributions from all
releases
- `binenv update -d`: update available distributions
- `binenv update kubectl helm`: update available versions for `kubectl` and
`helm`
Expand Down
8 changes: 4 additions & 4 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// localCmd represents the local command
func updateCmd(a *app.App) *cobra.Command {
var distributionsOnly, distributionsAlso, fromCache bool
var distributionsOnly, distributionsAlso, noCache bool

cmd := &cobra.Command{
Use: "update [--all|--distributions] [--cache]",
Expand All @@ -19,10 +19,10 @@ If not distribution is specified, versions for all distributions will be updated
a.SetVerbose(verbose)

if len(args) >= 1 {
a.Update(distributionsOnly, distributionsAlso, fromCache, args...)
a.Update(distributionsOnly, distributionsAlso, noCache, args...)
return
}
a.Update(distributionsOnly, distributionsAlso, fromCache)
a.Update(distributionsOnly, distributionsAlso, noCache)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
// Remove already selected distributions from completion
Expand All @@ -34,7 +34,7 @@ If not distribution is specified, versions for all distributions will be updated

cmd.Flags().BoolVarP(&distributionsOnly, "distributions", "d", false, "Update only distributions")
cmd.Flags().BoolVarP(&distributionsAlso, "all", "a", false, "Update distributions and distributions versions")
cmd.Flags().BoolVarP(&fromCache, "cache", "c", false, "Distributions versions will be updated from github cache")
cmd.Flags().BoolVarP(&noCache, "nocache", "f", false, "Distributions versions will be updated from each release and not from github cache")
return cmd
}

Expand Down
60 changes: 56 additions & 4 deletions distributions/cache.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
"0.1.0"
],
"glow": [
"1.3.0",
"1.2.1",
"1.2.0",
"1.1.0",
Expand Down Expand Up @@ -528,6 +529,36 @@
"1.8.0",
"1.7.5"
],
"hcloud": [
"1.20.0",
"1.19.1",
"1.19.0",
"1.18.0",
"1.17.0",
"1.16.2",
"1.16.1",
"1.16.0",
"1.15.0",
"1.14.0",
"1.13.0",
"1.12.0",
"1.11.0",
"1.10.0",
"1.9.1",
"1.9.0",
"1.8.0",
"1.7.0",
"1.6.1",
"1.6.0",
"1.5.0",
"1.4.0",
"1.3.2",
"1.3.1",
"1.3.0",
"1.2.0",
"1.1.0",
"1.0.0"
],
"helm": [
"3.4.2",
"3.4.1",
Expand Down Expand Up @@ -1015,6 +1046,9 @@
"3.8.3"
],
"lazygit": [
"0.24.2",
"0.24.1",
"0.24.0",
"0.23.7",
"0.23.6",
"0.23.5",
Expand All @@ -1041,12 +1075,10 @@
"0.17.3",
"0.17.2",
"0.17.0",
"0.16.2",
"0.16.0",
"0.15.7",
"0.15.6"
"0.16.2"
],
"logcli": [
"2.1.0",
"2.0.1",
"2.0.0",
"1.6.1",
Expand All @@ -1064,6 +1096,7 @@
"0.1.0"
],
"loki": [
"2.1.0",
"2.0.1",
"2.0.0",
"1.6.1",
Expand Down Expand Up @@ -1372,6 +1405,7 @@
"0.3.5"
],
"promtail": [
"2.1.0",
"2.0.1",
"2.0.0",
"1.6.1",
Expand Down Expand Up @@ -1454,6 +1488,24 @@
"0.0.2",
"0.0.1"
],
"sops": [
"3.6.1",
"3.6.0",
"3.5.0",
"3.4.0",
"3.3.1",
"3.3.0",
"3.2.0",
"3.1.1",
"3.1.0",
"3.0.5",
"3.0.4",
"3.0.3",
"3.0.2",
"3.0.1",
"3.0.0",
"2.0.10"
],
"ssllabs-scan": [
"1.4.0",
"1.3.0",
Expand Down
10 changes: 5 additions & 5 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func (a *App) Local(distribution, version string) error {
}

// Update fetches catalog of applications and updates available versions
func (a *App) Update(definitions, all bool, cache bool, which ...string) error {
func (a *App) Update(definitions, all bool, nocache bool, which ...string) error {
if definitions || all {
conf, err := getDistributionsFilePath()
if err != nil {
Expand Down Expand Up @@ -511,10 +511,10 @@ func (a *App) Update(definitions, all bool, cache bool, which ...string) error {
}

a.logger.Debug().Msgf("updating %d distributions", len(which))
if cache {
err = a.updateGithub()
} else {
if nocache {
err = a.updateLocally(which...)
} else {
err = a.updateGithub()
}
if err != nil {
return err
Expand All @@ -526,7 +526,7 @@ func (a *App) Update(definitions, all bool, cache bool, which ...string) error {
}

func (a *App) updateGithub() error {
a.logger.Info().Msgf("retrieving distribution list from %s", cacheURL)
a.logger.Info().Msgf("retrieving distribution cache from %s", cacheURL)
resp, err := http.Get(cacheURL)
if err != nil {
return err
Expand Down

0 comments on commit 6b03012

Please sign in to comment.