get

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &Z.Cmd{
	Name:    `get`,
	Summary: `install executables and applications on the host system [requires internet]`,
	Description: `
		The *get* command downloads a tools or applications from that providers releases or
		downloads page. Typically, tools are downloaded as a binary for fast and efficient access
		on the host platform.
		`,
	Other: []Z.Section{
		{
			Title: "Examples",
			Body: `
			ds get - list all available tools

			ds get arkade - download the Arkade binary`,
		},
	},
	Commands: []*Z.Cmd{

		help.Cmd,
	},
	Call: func(_ *Z.Cmd, args ...string) error {
		tools := MakeTools()
		arch, opSystem := GetClientArch()
		sort.Sort(tools)
		if len(args) == 0 {
			ListToolsTable(tools)
			return nil
		}
		tool := args[0]
		log.Printf("Looking up version for %q\n", tool)
		t, err := getTool(tool, tools)
		if err != nil {
			return err
		}

		version := t.Version
		if version == "" {
			version = "latest"
		}
		_, err = Download(&t, arch, opSystem, version)
		if err != nil {
			return err
		}

		err = PrintPostInstallMessage(t)
		if err != nil {
			return err
		}

		return nil
	},
}

Functions

func CopyFile

func CopyFile(src, dst string, permissions int) (int64, error)

CopyFile copies a source to a destination and applies permissions to that file.

func Download

func Download(tool *Tool, arch, opSystem, version string) (string, error)

Download is a public interface for downloading a file from a provided URL.

func GetBinaryName

func GetBinaryName(tool *Tool, os, arch, version string) (string, error)

GetBinaryName returns the name of a binary for the given tool or an error if the tool's template cannot be parsed or executed.

func GetClientArch

func GetClientArch() (arch, os string)

GetClientArch retrieves the host systems architecture and operating system. It will change the naming to a consistent format for linux/amd64. Further transformations of the architecture and operating system are then done elsewhere from a common base.

func GetDownloadURL

func GetDownloadURL(tool Tool, arch, opSystem, version string) (string, error)

GetDownloadURL returns the downloadable assets from GitHub for use in other functions.

func InitUserDir

func InitUserDir() (string, error)

InitUserDir will establish a location for the binaries to be stored.

func ListToolsTable

func ListToolsTable(tools Tools)

ListToolsTable returns a list of all supported tools in tabular format.

func LocalBinary

func LocalBinary(name, subdir string) (string, error)

LocalBinary returns the filepath for the binary in the users home directory.

func PostInstallationMessage

func PostInstallationMessage(localToolsStore ToolLocal) ([]byte, error)

PostInstallationMessage generates installation message after tool has been downloaded

func PrintPostInstallMessage

func PrintPostInstallMessage(t Tool) error

func Untar

func Untar(r io.Reader, target string, gzip bool) error

Untar untar a file to a target directory on the host it is running on.

func Unzip

func Unzip(r io.ReaderAt, size int64, target string) error

Unzip unzips files and puts them on the host system.

Types

type GithubAPIReleasesResponse

type GithubAPIReleasesResponse struct {
	Url       string `json:"url"`
	AssetsUrl string `json:"assets_url"`
	UploadUrl string `json:"upload_url"`
	HtmlUrl   string `json:"html_url"`
	Id        int    `json:"id"`
	Author    struct {
		Login             string `json:"login"`
		Id                int    `json:"id"`
		NodeId            string `json:"node_id"`
		AvatarUrl         string `json:"avatar_url"`
		GravatarId        string `json:"gravatar_id"`
		Url               string `json:"url"`
		HtmlUrl           string `json:"html_url"`
		FollowersUrl      string `json:"followers_url"`
		FollowingUrl      string `json:"following_url"`
		GistsUrl          string `json:"gists_url"`
		StarredUrl        string `json:"starred_url"`
		SubscriptionsUrl  string `json:"subscriptions_url"`
		OrganizationsUrl  string `json:"organizations_url"`
		ReposUrl          string `json:"repos_url"`
		EventsUrl         string `json:"events_url"`
		ReceivedEventsUrl string `json:"received_events_url"`
		Type              string `json:"type"`
		SiteAdmin         bool   `json:"site_admin"`
	} `json:"author"`
	NodeId          string    `json:"node_id"`
	TagName         string    `json:"tag_name"`
	TargetCommitish string    `json:"target_commitish"`
	Name            string    `json:"name"`
	Draft           bool      `json:"draft"`
	Prerelease      bool      `json:"prerelease"`
	CreatedAt       time.Time `json:"created_at"`
	PublishedAt     time.Time `json:"published_at"`
	Assets          []struct {
		Url      string `json:"url"`
		Id       int    `json:"id"`
		NodeId   string `json:"node_id"`
		Name     string `json:"name"`
		Label    string `json:"label"`
		Uploader struct {
			Login             string `json:"login"`
			Id                int    `json:"id"`
			NodeId            string `json:"node_id"`
			AvatarUrl         string `json:"avatar_url"`
			GravatarId        string `json:"gravatar_id"`
			Url               string `json:"url"`
			HtmlUrl           string `json:"html_url"`
			FollowersUrl      string `json:"followers_url"`
			FollowingUrl      string `json:"following_url"`
			GistsUrl          string `json:"gists_url"`
			StarredUrl        string `json:"starred_url"`
			SubscriptionsUrl  string `json:"subscriptions_url"`
			OrganizationsUrl  string `json:"organizations_url"`
			ReposUrl          string `json:"repos_url"`
			EventsUrl         string `json:"events_url"`
			ReceivedEventsUrl string `json:"received_events_url"`
			Type              string `json:"type"`
			SiteAdmin         bool   `json:"site_admin"`
		} `json:"uploader"`
		ContentType        string    `json:"content_type"`
		State              string    `json:"state"`
		Size               int       `json:"size"`
		DownloadCount      int       `json:"download_count"`
		CreatedAt          time.Time `json:"created_at"`
		UpdatedAt          time.Time `json:"updated_at"`
		BrowserDownloadUrl string    `json:"browser_download_url"`
	} `json:"assets"`
	TarballUrl    string `json:"tarball_url"`
	ZipballUrl    string `json:"zipball_url"`
	Body          string `json:"body"`
	MentionsCount int    `json:"mentions_count,omitempty"`
}

GithubAPIReleasesResponse is taken from the GitHub Releases API ref: https://docs.github.com/en/rest/releases/releases#list-releases

func FindGithubRelease

func FindGithubRelease(owner, repo string) ([]*GithubAPIReleasesResponse, error)

FindGithubRelease retrieves a response from GitHub's API for any valid repository in JSON format.

type Tool

type Tool struct {
	// Name of the tool
	Name string

	// Repo is the GitHub repo
	Repo string

	// Owner is the tool Repo owner, such as
	// derailed/k9s
	Owner string

	// Version to pull. An empty string means "latest"
	Version string

	// Description of what this tool does/is.
	Description string

	// NonBinary is used to determine if the tool is not a binary such as
	// kubetail which is a bash script
	NonBinary bool

	// BinaryTemplate is the naming convention for a binary from GitHub.
	// Using runtime.GOOS and runtime.GOARCH it is possible to determine the
	// binary name, and BinaryTemplate must match it.
	BinaryTemplate string

	// URLTemplate specifies a Go template for the download URL
	// override the OS, architecture and extension
	// All whitespace will be trimmed
	URLTemplate string
}

func (Tool) IsArchive

func (tool Tool) IsArchive(downloadURL string) (bool, error)

IsArchive determines if a binary is in archive format from the download URL.

type ToolLocal

type ToolLocal struct {
	Name    string
	Path    string
	BinPath string
}

type Tools

type Tools []Tool

func MakeTools

func MakeTools() Tools

func (Tools) Len

func (t Tools) Len() int

func (Tools) Less

func (t Tools) Less(i, j int) bool

func (Tools) Swap

func (t Tools) Swap(i, j int)

Jump to

Keyboard shortcuts

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