Documentation
¶
Index ¶
- Constants
- func Check(ctx context.Context, currentVersion string, cliVersioner Versioner) (current, latest semver.Version, shouldUpdate bool, err error)
- func CheckAsync(ctx context.Context, file config.File, configFilePath string, ...) (printResults func(io.Writer))
- type GitHub
- func (g *GitHub) Binary() string
- func (g *GitHub) BinaryName() string
- func (g GitHub) Download(ctx context.Context, version semver.Version) (string, error)
- func (g GitHub) GetAssetID(assets []*github.ReleaseAsset) (id int64, err error)
- func (g GitHub) GetReleaseID(ctx context.Context, version semver.Version) (id int64, err error)
- func (g GitHub) LatestVersion(ctx context.Context) (semver.Version, error)
- func (g *GitHub) SetAsset(name string)
- type GitHubOpts
- type GitHubRepoClient
- type RootCommand
- type Versioner
Constants ¶
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 ¶
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
BinaryName returns the binary name minus any extensions.
func (GitHub) Download ¶
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 (GitHub) LatestVersion ¶
LatestVersion calls the GitHub API to return the latest release as a semver.
func (*GitHub) SetAsset ¶
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 ¶
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 ¶
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, client api.HTTPClient, globals *config.Data) *RootCommand
NewRootCommand returns a new command registered in the parent.