activate_toolchain

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 17 Imported by: 0

README

activate-toolchain

A toolchain download and activation tool with various mirror sites embedded

Installation

You can either build binary from source, or just download pre-built binary.

Usage

Only support shell in POSIX environment.

eval "$(activate-toolchain node@16.2 jdk@17 maven@3.8)"

Or create a toolchains.txt file with each line a toolchain, and run

eval "$(activate-toolchain)"

Supported Toolchains and Version Examples

Toolchain Version Examples
node node@16, node@16.2, node@16.2.0
jdk jdk@8, jdk@8.0, jdk@8.0.372
maven maven@3, maven@3.8, maven@3.8.1
ossutil ossutil@1
pnpm pnpm@8, pnpm@8.9, pnpm@8.9.2
kubectl kubectl@1, kubectl@1.24, kubectl@1.24.1

Credits

GUO YANKE, MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToolchain

func AddToolchain(t Toolchain)

AddToolchain adds a toolchain to the list.

func AdvancedFetchFile

func AdvancedFetchFile(ctx context.Context, urls []string, localFile string) (err error)

AdvancedFetchFile detect fastest url from candidate urls and fetch file to local path

func DetectFastestURL

func DetectFastestURL(ctx context.Context, urls []string) (fastest string, err error)

DetectFastestURL detects the fastest url from urls

func FetchFile

func FetchFile(ctx context.Context, url string, localFile string) (err error)

func FetchJSON

func FetchJSON(ctx context.Context, url string, v interface{}) (err error)

FetchJSON fetch json from url and unmarshal to v

func FetchQueryHTML

func FetchQueryHTML(ctx context.Context, url string, sel string, fn func(i int, s *goquery.Selection)) (err error)

FetchQueryHTML fetches html from url, and find elements by selector, and call fn for each element

func FindBestVersion

func FindBestVersion(c *semver.Constraints, versions semver.Collection) (idx int, version *semver.Version, err error)

FindBestVersion finds the best match version from a list of versions. The returned index is the index of the version in the original list. The returned version is the best match version. The returned error is nil if there is a match, otherwise it is not nil. nil value in input versions will be ignored.

func FindBestVersionedItem

func FindBestVersionedItem[T any](c *semver.Constraints, items []T, fn func(v T) (version *semver.Version, err error)) (matched T, err error)

FindBestVersionedItem finds the best match version item from a list of items. If there is a match, the returned matched item is the best match item. The returned error is nil if there is a match, otherwise it is not nil. nil value and failed value in input items will be ignored.

func InstallArchive

func InstallArchive(ctx context.Context, opts InstallArchiveOptions) (dir string, err error)

InstallArchive installs an archive to a directory

func TryFetch

func TryFetch(ctx context.Context, url string) (delay time.Duration, err error)

TryFetch tries to fetch url, returns delay and error

Types

type InstallArchiveOptions

type InstallArchiveOptions struct {
	ProvideURLs    func() (urls []string, err error)
	Name           string
	File           string
	DirectoryLevel int
	DirectoryPath  string
}

type Spec

type Spec struct {
	// Name is the name of the toolchain.
	Name string
	// VersionRaw is the original version string, without any prefixing 'v'.
	VersionRaw string
	// Version is the version requested
	Version *semver.Version
	// VersionConstraints is the version constraints with tide.
	VersionConstraints *semver.Constraints
	// OS is the target operating system.
	// follows go convention, see https://go.dev/doc/install/source#environment for values.
	OS string
	// Arch is the target architecture.
	// follows go convention, see https://go.dev/doc/install/source#environment for values.
	Arch string
}

Spec is a toolchain spec. It is used to identify a toolchain.

func ParseSpec

func ParseSpec(s string) (spec Spec, err error)

ParseSpec parses a spec from string.

func (Spec) ConvertPlatform

func (s Spec) ConvertPlatform(remapOS, remapArch map[string]string) (os, arch string)

ConvertPlatform converts the platform strings to the target platform.

func (Spec) VersionHasMinor

func (s Spec) VersionHasMinor() bool

VersionHasMinor returns whether the version has minor.

func (Spec) VersionHasPatch

func (s Spec) VersionHasPatch() bool

VersionHasPatch returns whether the version has patch.

func (Spec) VersionedName

func (s Spec) VersionedName() string

type Toolchain

type Toolchain interface {
	// Support returns whether the toolchain supports the spec.
	Support(spec Spec) bool

	// Activate download, install and activate the toolchain
	Activate(ctx context.Context, spec Spec) (script string, err error)
}

Toolchain is an interface abstracting a toolchain.

func FindToolchain

func FindToolchain(spec Spec) (Toolchain, bool)

FindToolchain finds a toolchain by spec.

Directories

Path Synopsis
cmd
pkg
unarchive
Package unarchive
Package unarchive
toolchains
jdk

Jump to

Keyboard shortcuts

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