### Eget Examples: Installing and Managing Binaries Source: https://github.com/zyedidia/eget/blob/master/README.md Demonstrates various ways to use the 'eget' command-line tool to download and install pre-built binaries from GitHub repositories. Options include specifying tags, destinations, asset filters, and system architectures. ```shell eget zyedidia/micro --tag nightly eget jgm/pandoc --to /usr/local/bin eget junegunn/fzf eget neovim/neovim eget ogham/exa --asset ^musl eget --system darwin/amd64 sharkdp/fd eget BurntSushi/ripgrep eget -f eget.1 zyedidia/eget eget zachjs/sv2v eget https://go.dev/dl/go1.17.5.linux-amd64.tar.gz --file go --to ~/go1.17.5 eget --all --file '*' ActivityWatch/activitywatch ``` -------------------------------- ### Eget Command-Line Usage Examples Source: https://github.com/zyedidia/eget/blob/master/README.md Demonstrates how to use the Eget command-line tool. This includes a simple download command utilizing configuration and a more verbose command with explicit flags overriding configuration. ```bash eget zyedidia/micro ``` ```bash export EGET_GITHUB_TOKEN=ghp_1234567890 &&\ eget zyedidia/micro --to ~/.local/bin/micro --sha256 --asset static --asset .tar.gz ``` -------------------------------- ### Eget TOML Configuration Example Source: https://github.com/zyedidia/eget/blob/master/README.md Example configuration for Eget using TOML format. This snippet shows how to set global options and repository-specific settings like GitHub token, quiet mode, upgrade behavior, and asset filters. ```toml [global] github_token = "ghp_1234567890" quiet = false show_hash = false upgrade_only = true target = "./test" ["zyedidia/micro"] upgrade_only = false show_hash = true asset_filters = [ "static", ".tar.gz" ] target = "~/.local/bin/micro" ``` -------------------------------- ### Eget TOML Configuration Example Source: https://github.com/zyedidia/eget/blob/master/README.md Example TOML configuration file for Eget, demonstrating how to set global defaults and repository-specific settings. This allows users to customize Eget's behavior without specifying flags on the command line for every invocation. ```toml [global] target = "~/bin" ["zyedidia/micro"] target = "~/.local/bin" ``` -------------------------------- ### Basic Binary Installation from GitHub Repository Source: https://context7.com/zyedidia/eget/llms.txt Demonstrates various ways to install binaries from GitHub using Eget. This includes installing the latest or specific tagged releases, specifying installation directories, targeting different system architectures, filtering assets with regex, downloading without extraction, and verifying checksums. ```bash # Install latest release of micro editor eget zyedidia/micro # Install specific tagged release eget zyedidia/micro --tag nightly # Install to specific directory eget jgm/pandoc --to /usr/local/bin # Install for different system architecture eget --system darwin/amd64 sharkdp/fd # Filter assets using regex patterns eget ogham/exa --asset ^musl # Download multiple matching assets (anti-match pattern) eget BurntSushi/ripgrep --asset linux --asset ^musl # Extract specific file from release eget -f eget.1 zyedidia/eget # Download without extraction eget neovim/neovim --download-only # Only upgrade if newer version available eget junegunn/fzf --upgrade-only # Show SHA-256 hash of downloaded file eget zachjs/sv2v --sha256 # Verify checksum manually eget user/repo --verify-sha256=abc123def456... # Check GitHub API rate limit status eget --rate ``` -------------------------------- ### Install prebuilt binary from GitHub release with Eget Source: https://github.com/zyedidia/eget/blob/master/man/eget.md This example demonstrates how to use Eget to download and extract a prebuilt binary from a GitHub repository's latest release. Eget automatically finds a suitable binary for your system and extracts it to the current directory or a specified location. ```bash eget user/repo eget --to /usr/local/bin user/repo ``` -------------------------------- ### Environment Variables and Configuration for Eget Source: https://context7.com/zyedidia/eget/llms.txt Illustrates how to configure Eget using environment variables. This includes setting the GitHub token for API authentication, specifying the default installation directory, and indicating a custom configuration file location. ```bash # Set GitHub token for API authentication (60 req/hr → 5000 req/hr) export EGET_GITHUB_TOKEN="ghp_1234567890abcdef" export GITHUB_TOKEN="ghp_1234567890abcdef" # fallback # Read token from file export EGET_GITHUB_TOKEN="@~/.github-token" # Set default installation directory export EGET_BIN="$HOME/.local/bin" # Specify custom config file location export EGET_CONFIG="$HOME/.config/eget/custom.toml" # Install using environment defaults eget user/repo ``` -------------------------------- ### TOML Configuration File Structure for Eget Source: https://context7.com/zyedidia/eget/llms.txt Presents the structure of Eget's TOML configuration file, demonstrating how to define global settings and repository-specific overrides. This allows for persistent configuration of download and installation parameters. ```toml # ~/.eget.toml or ~/.config/eget/eget.toml [global] github_token = "ghp_1234567890abcdef" quiet = false show_hash = false upgrade_only = true target = "~/.local/bin" system = "linux/amd64" all = false download_only = false download_source = false file = "*" ["zyedidia/micro"] upgrade_only = false show_hash = true asset_filters = [ "static", ".tar.gz" ] target = "~/.local/bin/micro" tag = "nightly" verify_sha256 = "abc123def456..." disable_ssl = false ["neovim/neovim"] asset_filters = [ "linux64", "^musl" ] target = "~/apps/nvim" file = "nvim" ["BurntSushi/ripgrep"] system = "darwin/arm64" quiet = true ``` -------------------------------- ### Eget Command Expansion with TOML Configuration Source: https://context7.com/zyedidia/eget/llms.txt Illustrates how Eget expands a simple command-line invocation into a more detailed one, incorporating settings defined in the TOML configuration file. It also shows how to download all repositories defined in the config. ```bash # With above config, this command: eget zyedidia/micro # Automatically expands to: eget zyedidia/micro --to ~/.local/bin/micro --sha256 --asset static --asset .tar.gz --tag nightly # Download all repositories defined in config eget --download-all ``` -------------------------------- ### Eget Installation from Source (Go) Source: https://github.com/zyedidia/eget/blob/master/README.md Installs the latest released version of Eget directly from source using the Go command-line tool. ```go go install github.com/zyedidia/eget@latest ``` -------------------------------- ### Go: Load and Manage Eget Configuration Source: https://context7.com/zyedidia/eget/llms.txt This Go code demonstrates how to initialize and load Eget's configuration, which follows a specific search order including environment variables and TOML files. It shows how to access global and repository-specific settings, apply configurations to command-line flags, and set environment variables from configuration. ```go // Example: Load and initialize configuration config, err := InitializeConfig() if err != nil { log.Fatal(err) } // Configuration search order: // 1. $EGET_CONFIG (environment variable) // 2. ~/.eget.toml // 3. ./eget.toml (current directory) // 4. $XDG_CONFIG_HOME/eget/eget.toml (or $LOCALAPPDATA on Windows) // Example: Access global settings fmt.Printf("Global target: %s\n", config.Global.Target) fmt.Printf("Upgrade only: %v\n", config.Global.UpgradeOnly) if config.Global.GithubToken != "" { os.Setenv("EGET_GITHUB_TOKEN", config.Global.GithubToken) } // Example: Access repository-specific settings if repoConfig, exists := config.Repositories["zyedidia/micro"]; exists { fmt.Printf("Micro target: %s\n", repoConfig.Target) fmt.Printf("Asset filters: %v\n", repoConfig.AssetFilters) fmt.Printf("Tag: %s\n", repoConfig.Tag) } // Example: Apply config to flags var opts Flags var cli CliFlags flagparser := flags.NewParser(&cli, flags.PassDoubleDash|flags.PrintErrors) err = SetGlobalOptionsFromConfig(config, flagparser, &opts, cli) if err != nil { log.Fatal(err) } target := "zyedidia/micro" err = SetProjectOptionsFromConfig(config, flagparser, &opts, cli, target) if err != nil { log.Fatal(err) } fmt.Printf("Final output path: %s\n", opts.Output) fmt.Printf("Asset filters: %v\n", opts.Asset) ``` -------------------------------- ### Eget Quick-Install Script Source: https://github.com/zyedidia/eget/blob/master/README.md Provides shell commands to download and execute the Eget quick-install script. It includes steps for verification using shasum and options for direct execution or piping through sh. ```shell curl -o eget.sh https://zyedidia.github.io/eget.sh shasum -a 256 eget.sh # verify with hash below bash eget.sh ``` ```shell curl https://zyedidia.github.io/eget.sh | sh ``` -------------------------------- ### Customize installation directory with Eget's --to flag Source: https://github.com/zyedidia/eget/blob/master/man/eget.md This example shows how to use the --to flag with Eget to specify a custom directory where the extracted binary should be placed, overriding the default current directory or EGET_BIN environment variable. ```bash eget --to ~/bin user/repo eget --to /opt/app user/repo ``` -------------------------------- ### Eget Installation via Chocolatey Source: https://github.com/zyedidia/eget/blob/master/README.md Installs the Eget tool using the Chocolatey package manager on Windows systems. ```shell choco install eget ``` -------------------------------- ### Eget Configuration Example (TOML) Source: https://github.com/zyedidia/eget/blob/master/man/eget.md Demonstrates how to configure Eget using a TOML file. This includes setting global options like download targets and repository-specific overrides for upgrade behavior, hash display, asset filtering, and target paths. ```toml [global] target = "~/bin" ["zyedidia/micro"] target = "~/.local/bin" ``` ```toml [global] github_token = "ghp_1234567890" quiet = false show_hash = false upgrade_only = true target = "./test" ["zyedidia/micro"] upgrade_only = false show_hash = true asset_filters = [ "static", ".tar.gz" ] target = "~/.local/bin/micro" ``` -------------------------------- ### Eget Installation via Homebrew Source: https://github.com/zyedidia/eget/blob/master/README.md Installs the Eget tool using the Homebrew package manager on macOS or Linux systems. ```shell brew install eget ``` -------------------------------- ### Eget Build from Source (Make) Source: https://github.com/zyedidia/eget/blob/master/README.md Builds the Eget binary from its source code repository using the Make utility. This method also allows for generating man pages. ```shell git clone https://github.com/zyedidia/eget cd eget make build ``` -------------------------------- ### Direct URL and Local File Extraction with Eget Source: https://context7.com/zyedidia/eget/llms.txt Shows how to use Eget to download and extract binaries directly from a URL or from a local archive file. It also covers extracting all files matching a glob pattern. ```bash # Download and extract from direct URL eget https://go.dev/dl/go1.17.5.linux-amd64.tar.gz --file go --to ~/go1.17.5 # Extract from local archive file eget /path/to/archive.tar.gz --file binary_name # Extract all files matching glob pattern eget --all --file '*' ActivityWatch/activitywatch ``` -------------------------------- ### Go: Interact with GitHub API Rate Limits and Authentication Source: https://context7.com/zyedidia/eget/llms.txt This Go code illustrates how to check GitHub API rate limits using `GetRateLimit` and how to set up an authenticated HTTP request with a GitHub token. It also shows how to retrieve the GitHub token, including reading it from a file like `~/.github-token`. ```go // Example: Check API rate limit rateLimit, err := GetRateLimit() if err != nil { log.Fatal(err) } fmt.Printf("Limit: %d requests/hour\n", rateLimit.Limit) fmt.Printf("Remaining: %d requests\n", rateLimit.Remaining) fmt.Printf("Reset time: %v\n", rateLimit.ResetTime()) fmt.Printf("Time until reset: %v\n", time.Until(rateLimit.ResetTime())) // Example: Authenticated request with token os.Setenv("EGET_GITHUB_TOKEN", "ghp_1234567890abcdef") req, err := http.NewRequest("GET", "https://api.github.com/repos/user/repo/releases/latest", nil) if err != nil { log.Fatal(err) } req = SetAuthHeader(req) // Adds Authorization header if token is set resp, err := http.DefaultClient.Do(req) if err != nil { log.Fatal(err) } defer resp.Body.Close() // Example: Read token from file os.Setenv("EGET_GITHUB_TOKEN", "@~/.github-token") token, err := getGithubToken() // Reads from ~/.github-token and strips trailing newlines ``` -------------------------------- ### Detect Platform-Specific Release Assets (Go) Source: https://context7.com/zyedidia/eget/llms.txt Implements the Detector interface to select the most appropriate asset from a list for the target operating system and architecture. It supports automatic detection for the current system, cross-platform detection, and filtering based on asset names or patterns. ```go // Detector selects the appropriate asset for target OS/architecture type Detector interface { Detect(assets []string) (string, []string, error) } // Example: Auto-detect for current system detector, err := NewSystemDetector(runtime.GOOS, runtime.GOARCH) if err != nil { log.Fatal(err) } assets := []string{ "https://github.com/user/repo/releases/download/v1.0.0/tool-linux-amd64.tar.gz", "https://github.com/user/repo/releases/download/v1.0.0/tool-darwin-arm64.tar.gz", "https://github.com/user/repo/releases/download/v1.0.0/tool-windows-amd64.zip", } url, candidates, err := detector.Detect(assets) if err != nil && len(candidates) > 1 { fmt.Println("Multiple matches found:") for i, c := range candidates { fmt.Printf(" %d) %s\n", i+1, c) } // User must manually select } else if err != nil { log.Fatal(err) } // url contains the single matching asset for current system // Example: Cross-platform detection crossDetector, err := NewSystemDetector("darwin", "arm64") url, _, err := crossDetector.Detect(assets) // url: "https://github.com/user/repo/releases/download/v1.0.0/tool-darwin-arm64.tar.gz" // Example: Asset filtering with anti-patterns assetDetector := &SingleAssetDetector{ Asset: "musl", Anti: true, // exclude assets containing "musl" } url, candidates, err := assetDetector.Detect(assets) // Example: Chain multiple detectors chain := &DetectorChain{ detectors: []Detector{ &SingleAssetDetector{Asset: "linux", Anti: false}, &SingleAssetDetector{Asset: "musl", Anti: true}, }, system: detector, } url, _, err := chain.Detect(assets) // Filters: contains "linux" → excludes "musl" → matches OS/arch ``` -------------------------------- ### Download Files with Progress Bar using Go Source: https://context7.com/zyedidia/eget/llms.txt The Download function in Go facilitates fetching files from a given URL, writing them to an output writer, and displaying progress using a configurable progress bar. It allows for customization of the progress bar's appearance and behavior, silent downloads by discarding output, and downloading from local file paths. Dependencies include 'bytes', 'io', 'os', 'time', and the 'pb' (progress bar) library. ```go // Download fetches files with progress tracking func Download(url string, out io.Writer, getbar func(size int64) *pb.ProgressBar) error // Example: Download with progress bar buf := &bytes.Buffer{} err := Download( "https://github.com/user/repo/releases/download/v1.0.0/binary-linux-amd64.tar.gz", buf, func(size int64) *pb.ProgressBar { return pb.NewOptions64(size, pb.OptionSetWriter(os.Stderr), pb.OptionShowBytes(true), pb.OptionSetWidth(10), pb.OptionThrottle(65*time.Millisecond), pb.OptionShowCount(), pb.OptionSpinnerType(14), pb.OptionFullWidth(), pb.OptionSetDescription("Downloading"), pb.OptionOnCompletion(func() { fmt.Fprint(os.Stderr, "\n") }), pb.OptionSetTheme(pb.Theme{ Saucer: "=", SaucerHead: ">", SaucerPadding: " ", BarStart: "[", BarEnd: "]", }), ) }, ) if err != nil { log.Fatal(err) } downloadedData := buf.Bytes() fmt.Printf("Downloaded %d bytes\n", len(downloadedData)) // Example: Download from local file localBuf := &bytes.Buffer{} err = Download("/path/to/local/archive.tar.gz", localBuf, func(size int64) *pb.ProgressBar { return pb.NewOptions64(size) }) // Example: Silent download (no progress bar) silentBuf := &bytes.Buffer{} err = Download(url, silentBuf, func(size int64) *pb.ProgressBar { return pb.NewOptions64(size, pb.OptionSetWriter(io.Discard)) }) ``` -------------------------------- ### Extract a local archive file with Eget Source: https://github.com/zyedidia/eget/blob/master/man/eget.md This example illustrates using Eget to extract an archive file that is already present on the local system. Eget treats the local file path similar to a URL for extraction purposes. ```bash eget /path/to/local/archive.zip ``` -------------------------------- ### Eget Command-Line Usage Source: https://github.com/zyedidia/eget/blob/master/README.md This section outlines the available command-line options for the Eget tool. It includes flags for specifying release tags, pre-releases, source code downloads, target directories, system architectures, file selection, quiet operation, download-only mode, upgrade behavior, asset filtering, checksum verification, rate limiting information, file removal, version display, help messages, downloading all projects, and disabling SSL verification. ```bash Usage: eget [OPTIONS] TARGET Application Options: -t, --tag= tagged release to use instead of latest --pre-release include pre-releases when fetching the latest version --source download the source code for the target repo instead of a release --to= move to given location after extracting -s, --system= target system to download for (use "all" for all choices) -f, --file= glob to select files for extraction --all extract all candidate files -q, --quiet only print essential output -d, --download-only stop after downloading the asset (no extraction) --upgrade-only only download if release is more recent than current version -a, --asset= download a specific asset containing the given string; can be specified multiple times for additional filtering; use ^ for anti-match --sha256 show the SHA-256 hash of the downloaded asset --verify-sha256= verify the downloaded asset checksum against the one provided --rate show GitHub API rate limiting information -r, --remove remove the given file from $EGET_BIN or the current directory -v, --version show version information -h, --help show this help message -D, --download-all download all projects defined in the config file -k, --disable-ssl disable SSL verification for download ``` -------------------------------- ### Find Release Assets from GitHub or Direct URL (Go) Source: https://context7.com/zyedidia/eget/llms.txt Implements the Finder interface to retrieve asset URLs for a GitHub repository or a direct download link. Supports finding latest releases, specific tags, prereleases, and direct URLs. It can also be used to download source code archives. ```go // Finder returns asset URLs for a GitHub repository or direct download type Finder interface { Find() ([]string, error) } // Example: Finding assets from GitHub release finder := &GithubAssetFinder{ Repo: "zyedidia/micro", Tag: "latest", // or "tags/v2.0.13" Prerelease: false, MinTime: time.Time{}, // minimum release time for upgrade checks } assets, err := finder.Find() if err != nil { if errors.Is(err, ErrNoUpgrade) { fmt.Println("Current version is up to date") return } log.Fatal(err) } // assets contains: []string{ // "https://github.com/zyedidia/micro/releases/download/v2.0.13/micro-2.0.13-linux64.tar.gz", // "https://github.com/zyedidia/micro/releases/download/v2.0.13/micro-2.0.13-osx.tar.gz", // "https://github.com/zyedidia/micro/releases/download/v2.0.13/micro-2.0.13-win64.zip", // ... // } // Example: Direct URL download directFinder := &DirectAssetFinder{ URL: "https://example.com/tool-v1.2.3-linux-amd64.tar.gz", } assets, err := directFinder.Find() // assets: []string{"https://example.com/tool-v1.2.3-linux-amd64.tar.gz"} // Example: Downloading source code sourceFinder := &GithubSourceFinder{ Tool: "eget", Repo: "zyedidia/eget", Tag: "master", // or specific branch/tag } assets, err := sourceFinder.Find() // assets: []string{"https://github.com/zyedidia/eget/tarball/master/eget.tar.gz"} ``` -------------------------------- ### Extract specific files or directories using Eget's --file flag Source: https://github.com/zyedidia/eget/blob/master/man/eget.md This example demonstrates how to use the --file flag to specify which file or directory within an archive should be extracted. This is particularly useful when an archive contains multiple components and only a specific one is needed. ```bash eget https://go.dev/dl/go1.17.5.linux-amd64.tar.gz --file go --to ~/go1.17.5 ``` -------------------------------- ### Verify File Checksums using Go Source: https://context7.com/zyedidia/eget/llms.txt The Verifier interface in Go is used for validating the integrity of downloaded files using checksums, primarily SHA-256. It supports manual verification against a provided hash, automatic verification by fetching checksums from an asset file URL, printing the checksum without verification, or completely skipping verification. Errors during verification typically indicate a checksum mismatch. ```go // Verifier validates downloaded file integrity type Verifier interface { Verify(b []byte) error } // Example: Manual SHA-256 verification verifier, err := NewSha256Verifier("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") if err != nil { log.Fatal(err) } downloadedData := []byte{ /* downloaded file content */ } err = verifier.Verify(downloadedData) if err != nil { if shaErr, ok := err.(*Sha256Error); ok { fmt.Printf("Checksum mismatch!\n") fmt.Printf("Expected: %x\n", shaErr.Expected) fmt.Printf("Got: %x\n", shaErr.Got) } log.Fatal(err) } fmt.Println("Checksum verified successfully") // Example: Automatic verification from .sha256 asset file verifier = &Sha256AssetVerifier{ AssetURL: "https://github.com/user/repo/releases/download/v1.0.0/binary-linux-amd64.tar.gz.sha256", } err = verifier.Verify(downloadedData) // Example: Print checksum without verification printer := &Sha256Printer{} printer.Verify(downloadedData) // Output: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 // Example: Skip verification noVerify := &NoVerifier{} noVerify.Verify(downloadedData) // always returns nil ``` -------------------------------- ### Extract Archives and Files using Go Source: https://context7.com/zyedidia/eget/llms.txt The Extractor interface in Go allows for unpacking various archive formats like tar.gz and zip. It supports extracting specific files using glob patterns, all files, or handling single compressed files. Dependencies include standard library packages like 'archive/tar', 'compress/gzip', and 'path/filepath'. It takes archive data and optional parameters to determine extraction behavior, returning extracted file information or errors. ```go // Extractor extracts files from downloaded archives type Extractor interface { Extract(data []byte, multiple bool) (ExtractedFile, []ExtractedFile, error) } // Example: Extract binary by name chooser := &BinaryChooser{Tool: "ripgrep"} extractor := NewExtractor("ripgrep-13.0.0-linux-amd64.tar.gz", "ripgrep", chooser) archiveData := []byte{ /* downloaded tar.gz data */ } file, candidates, err := extractor.Extract(archiveData, false) if err != nil && len(candidates) > 1 { fmt.Println("Multiple executables found:") for _, c := range candidates { fmt.Printf(" - %s\n", c.ArchiveName) } } else if err != nil { log.Fatal(err) } // Write extracted file to disk outputPath := "/usr/local/bin/rg" err = file.Extract(outputPath) if err != nil { log.Fatal(err) } fmt.Printf("Extracted %s to %s\n", file.ArchiveName, outputPath) // Example: Extract specific file with glob pattern globChooser, err := NewGlobChooser("bin/*") extractor = NewExtractor("app-v1.0.0.tar.gz", "app", globChooser) file, _, err = extractor.Extract(archiveData, false) // Example: Extract all files extractor = NewExtractor("package.zip", "package", &GlobChooser{all: true}) _, allFiles, err := extractor.Extract(archiveData, true) for _, f := range allFiles { destPath := filepath.Join("/opt/app", f.Name) if err := f.Extract(destPath); err != nil { log.Printf("Failed to extract %s: %v", f.ArchiveName, err) } } // Example: Single compressed file (no archive) extractor = &SingleFileExtractor{ Name: "binary.gz", Rename: "binary", Decompress: func(r io.Reader) (io.Reader, error) { return gzip.NewReader(r) }, } file, _, err = extractor.Extract(compressedData, false) ``` -------------------------------- ### Download and extract directly from a URL with Eget Source: https://github.com/zyedidia/eget/blob/master/man/eget.md This showcases Eget's capability to download and extract files directly from a provided URL. This is useful for sources other than GitHub releases or when a direct link to the asset is known. ```bash eget https://example.com/binary.tar.gz ``` -------------------------------- ### Configure Eget to use GitHub token for increased API limits Source: https://github.com/zyedidia/eget/blob/master/man/eget.md This demonstrates how to set the GITHUB_TOKEN or EGET_GITHUB_TOKEN environment variable to authenticate with the GitHub API, allowing for higher request rates. EGET_GITHUB_TOKEN takes precedence if both are set. ```bash # Using GITHUB_TOKEN export GITHUB_TOKEN="your_github_token" eget user/repo # Using EGET_GITHUB_TOKEN (takes precedence) export EGET_GITHUB_TOKEN="your_eget_github_token" eget user/repo # Reading token from a file export EGET_GITHUB_TOKEN="@/path/to/your/token/file" eget user/repo ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.