upgrade

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfigDir added in v1.1.0

func DefaultConfigDir() string

DefaultConfigDir returns config directory.

Path precedence: 1. VERSION_CONFIG_DIR, 2. XDG_CONFIG_HOME, 3. HOME.

Types

type GitHubDetector

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

GitHubDetector provides functionality to check GitHub for project's latest release.

func NewGitHubDetector

func NewGitHubDetector(owner, repo string, opts ...Options) *GitHubDetector

NewGitHubDetector returns GitHubDetector instance.

func (*GitHubDetector) LookForGreaterRelease added in v1.1.0

LookForGreaterRelease checks project's latest release. In most cases, PrintIfFoundGreater is better option.

func (*GitHubDetector) LookForLatestRelease

LookForLatestRelease checks project's latest release. In most cases, PrintIfFoundGreater is better option.

Deprecated and will be removed in 1.4.0 release, use LookForGreaterRelease instead.

Old: LookForLatestRelease(upgrade.LookForLatestReleaseInput{CurrentVersion: currentVersion})
New: LookForGreaterRelease(upgrade.LookForGreaterReleaseInput{CurrentVersion: currentVersion})

func (*GitHubDetector) PrintIfFoundGreater

func (gh *GitHubDetector) PrintIfFoundGreater(w io.Writer, currentVersion string) error

PrintIfFoundGreater prints an upgrade notice if a newer version is available. It's a syntax sugar for using the LookForGreaterRelease and Render functions.

func (*GitHubDetector) Render

func (gh *GitHubDetector) Render(info *Info, isSmartTerminal bool) (string, error)

Render returns rendered input version with configured style.

type Info

type Info struct {
	// Version represents a current CLI version.
	Version string
	// NewVersion represents the newest CLI version.
	NewVersion string
	// ReleaseURL represents the GitHub release URL.
	ReleaseURL string
	// IsFromCache if true, the external call was not executed and version was taken from state file.
	IsFromCache bool
}

Info contains upgrade related information.

type IsVerGreaterFunc

type IsVerGreaterFunc func(current string, new string) bool

IsVerGreaterFunc represents version check function signature.

type LookForGreaterReleaseInput added in v1.1.0

type LookForGreaterReleaseInput struct {
	CurrentVersion string
}

LookForGreaterReleaseInput holds input data for LookForGreaterRelease function.

type LookForGreaterReleaseOutput added in v1.1.0

type LookForGreaterReleaseOutput struct {
	Found       bool
	ReleaseInfo *Info
}

LookForGreaterReleaseOutput holds output data for LookForGreaterRelease function.

type LookForLatestReleaseInput

type LookForLatestReleaseInput struct {
	CurrentVersion string
}

LookForLatestReleaseInput holds input data for LookForLatestRelease function.

type LookForLatestReleaseOutput

type LookForLatestReleaseOutput struct {
	Found       bool
	ReleaseInfo *Info
}

LookForLatestReleaseOutput holds output data for LookForLatestRelease function.

type Options

type Options func(options *GitHubDetector)

Options represents function mutating default options.

func WithConfigDir added in v1.1.0

func WithConfigDir(dir string) Options

WithConfigDir sets the config dir path where cache is stored (state file). If not set, directory is selected in such order:

  1. VERSION_CONFIG_DIR environment variable
  2. XDG_CONFIG_HOME environment variable
  3. os.UserHomeDir()

func WithFormatting

func WithFormatting(formatting *style.Formatting) Options

WithFormatting sets a custom pretty formatting.

func WithIsVersionGreater

func WithIsVersionGreater(comparator IsVerGreaterFunc) Options

WithIsVersionGreater sets a custom function to compare release versions. Defaults to a SemVer check.

func WithLayout

func WithLayout(layout *style.Layout) Options

WithLayout sets a custom pretty layout.

func WithMinElapseTimeForRecheck

func WithMinElapseTimeForRecheck(interval time.Duration) Options

WithMinElapseTimeForRecheck sets the minimum time that must elapse before checking for a new release. When interval > 0, a state file is created. If interval = 0, state file is not created and each time external call is executed. Defaults to 0.

func WithPostRenderHook

func WithPostRenderHook(renderer PostRenderFunc) Options

WithPostRenderHook sets a custom post render function.

func WithRenderer

func WithRenderer(renderer RenderFunc) Options

WithRenderer sets a custom renderer function.

func WithStateFileName added in v1.1.0

func WithStateFileName(fileName string) Options

WithStateFileName sets the state file name. Defaults to {repo_owner}/{repo_name}

func WithStyle

func WithStyle(cfg *style.Config) Options

WithStyle sets a custom pretty style.

func WithUpdateCheckTimeout

func WithUpdateCheckTimeout(timeout time.Duration) Options

WithUpdateCheckTimeout sets max duration time for update check operation. Defaults to 10s.

type PostRenderFunc

type PostRenderFunc func(body string, isSmartTerminal bool) (string, error)

PostRenderFunc represents post render function signature.

type RenderFunc

type RenderFunc func(in *Info, isSmartTerminal bool) (string, error)

RenderFunc represents render function signature.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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