update

package
v1.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultAssetFormat = "%s_v%s_%s-%s%s"

DefaultAssetFormat represents the standard GitHub release asset name format.

Interpolation placeholders: - binary name - semantic version - os - arch - archive file extension (e.g. ".tar.gz" or ".zip")

Variables

This section is empty.

Functions

func Check

func Check(ctx context.Context, currentVersion string, cliVersioner Versioner) (current, latest semver.Version, shouldUpdate bool, err error)

Check if the CLI can be updated.

func CheckAsync

func CheckAsync(ctx context.Context, file config.File, configFilePath string, currentVersion string, cliVersioner Versioner, in io.Reader, out io.Writer) (printResults func(io.Writer))

CheckAsync is a helper function for Check. If the app config's LastChecked time has past the specified TTL, launch a goroutine to perform the Check using the provided context. Return a function that will print an informative message to the writer if there is a newer version available.

Callers should invoke CheckAsync via

f := CheckAsync(...)
defer f()

Types

type GitHub

type GitHub struct {
	// contains filtered or unexported fields
}

GitHub is a versioner that uses GitHub releases.

func NewGitHub

func NewGitHub(opts GitHubOpts) *GitHub

NewGitHub returns a usable GitHub versioner utilizing the provided token.

func (*GitHub) Binary

func (g *GitHub) Binary() string

Binary returns the configured binary output name.

NOTE: For some operating systems this might include a file extension, such as .exe for Windows.

func (*GitHub) BinaryName added in v0.42.0

func (g *GitHub) BinaryName() string

BinaryName returns the binary name minus any extensions.

func (GitHub) Download

func (g GitHub) Download(ctx context.Context, version semver.Version) (string, error)

Download implements the Versioner interface.

Downloading, unarchiving and changing the file modes is done inside a temporary directory within $TMPDIR. On success, the resulting file is renamed to a temporary one within $TMPDIR, and returned. The temporary directory and its content are always removed.

func (GitHub) GetAssetID added in v0.42.0

func (g GitHub) GetAssetID(assets []*github.ReleaseAsset) (id int64, err error)

func (GitHub) GetReleaseID added in v0.42.0

func (g GitHub) GetReleaseID(ctx context.Context, version semver.Version) (id int64, err error)

func (GitHub) LatestVersion

func (g GitHub) LatestVersion(ctx context.Context) (semver.Version, error)

LatestVersion calls the GitHub API to return the latest release as a semver.

func (*GitHub) SetAsset

func (g *GitHub) SetAsset(name string)

SetAsset allows configuring the release asset format.

NOTE: This existed because the CLI project was originally using a different release asset name format to the Viceroy project. Although the two projects are now aligned we've kept this feature in case there are any changes between the two projects in the future, or if we have to call out to more external binaries from within the CLI.

type GitHubOpts

type GitHubOpts struct {
	Org    string
	Repo   string
	Binary string
}

GitHubOpts represents options to be passed to NewGitHub.

type GitHubRepoClient added in v0.42.0

type GitHubRepoClient interface {
	GetLatestRelease(ctx context.Context, owner, repo string) (*github.RepositoryRelease, *github.Response, error)
	GetRelease(ctx context.Context, owner, repo string, id int64) (*github.RepositoryRelease, *github.Response, error)
	DownloadReleaseAsset(ctx context.Context, owner, repo string, id int64, followRedirectsClient *http.Client) (rc io.ReadCloser, redirectURL string, err error)
	ListReleases(ctx context.Context, owner, repo string, opts *github.ListOptions) ([]*github.RepositoryRelease, *github.Response, error)
}

GitHubRepoClient describes the GitHub client behaviours we need.

type RootCommand

type RootCommand struct {
	cmd.Base
	// contains filtered or unexported fields
}

RootCommand is the parent command for all subcommands in this package. It should be installed under the primary root command.

func NewRootCommand

func NewRootCommand(parent cmd.Registerer, configFilePath string, cliVersioner Versioner, globals *config.Data) *RootCommand

NewRootCommand returns a new command registered in the parent.

func (*RootCommand) Exec

func (c *RootCommand) Exec(in io.Reader, out io.Writer) error

Exec implements the command interface.

type Versioner

type Versioner interface {
	Binary() string
	BinaryName() string
	Download(context.Context, semver.Version) (filename string, err error)
	LatestVersion(context.Context) (semver.Version, error)
	SetAsset(name string)
}

Versioner describes a source of CLI release artifacts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL