installer

package
v0.0.0-...-254d9fd Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Example (CreateTempDir)

[CreateTempDir] shows temporary directory creation and handling

installer := &Installer{
	config: Config{
		TempDir: "/tmp",
	},
}

// Demonstrate directory pattern
pattern := filepath.Join(installer.config.TempDir, "install_*")
fmt.Printf("Directory pattern: %s\n", pattern)
fmt.Printf("Base temp dir: %s\n", filepath.Base(installer.config.TempDir))
Output:
Directory pattern: /tmp/install_*
Base temp dir: tmp
Example (GetCodeFormat)

Test the [getCodeFormat] function, which returns the format of the snippet

line := "```bash"
codeFormat := getCodeFormat(line)
fmt.Printf("%s", codeFormat)
Output:
bash
Example (GetName)

Test the [getName] function, which returns the name of the snippet

line := "/*##NAME:example.go##*/"
fileName := getName(line)
fmt.Printf("%s", fileName)
Output:
example.go
Example (NewInstaller)

NewInstaller demonstrates creating a new installer instance with configuration

// Create test configuration
homeDir, err := os.UserHomeDir()
if err != nil {
	fmt.Printf("Error getting home directory: %v\n", err)
	return
}

config := Config{
	TargetDir: filepath.Join(homeDir, ".local", "bin"),
	TempDir:   "/tmp",
}

// Initialize installer with test repository
repos := []string{"cli/cli"}
installer, err := NewInstaller(config, repos)
if err != nil {
	fmt.Printf("Error creating installer: %v\n", err)
	return
}

fmt.Printf("Target directory: %s\n", filepath.Base(installer.config.TargetDir))
fmt.Printf("Number of repos: %d\n", len(installer.repos))
Output:
Target directory: bin
Number of repos: 1
Example (NewRepo)

NewRepo shows how to create and validate a new repository instance

// Test valid repository URL
validRepo := "cli/cli"
repo, err := NewRepo(validRepo)
if err != nil {
	fmt.Printf("Error with valid repo: %v\n", err)
} else {
	fmt.Printf("Valid repo - Owner: %s, Name: %s\n", repo.Owner, repo.Name)
}

invalidRepo := "invalid://repo"
_, err = NewRepo(invalidRepo)
if err != nil {
	fmt.Printf("Invalid repo error: %v\n", err)
}
Output:
Valid repo - Owner: cli, Name: cli
Invalid repo error: invalid repository URL format. Must be 'owner/repo'
Example (ValidateRepoUrl)

[ValidateRepoUrl] demonstrates repository URL validation logic

// Test cases for URL validation
urls := []string{
	"owner/repo",
	"owner/repo/extra",
	"",
	"owner",
}

for _, url := range urls {
	parts, err := validateRepoUrl(url)
	if err != nil {
		fmt.Printf("URL '%s' invalid: %v\n", url, err)
	} else {
		fmt.Printf("URL '%s' valid: owner='%s' repo='%s'\n", url, parts[0], parts[1])
	}
}
Output:
URL 'owner/repo' valid: owner='owner' repo='repo'
URL 'owner/repo/extra' invalid: invalid repository URL format. Must be 'owner/repo'
URL '' invalid: invalid repository URL format. Must be 'owner/repo'
URL 'owner' invalid: invalid repository URL format. Must be 'owner/repo'

Index

Examples

Constants

This section is empty.

Variables

View Source
var TOOLBOX = []string{
	"cli/cli",
	"mikefarah/yq",
	"junegunn/fzf",
}

Functions

func ChoseSnippet

func ChoseSnippet() (string, error)

Types

type Completer

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

func NewCompleter

func NewCompleter(command string) *Completer

func (*Completer) Generate

func (c *Completer) Generate() (string, error)

func (*Completer) Save

func (c *Completer) Save() error

func (*Completer) SetOutputDir

func (c *Completer) SetOutputDir(dir string) *Completer

func (*Completer) SetShell

func (c *Completer) SetShell(shell string) *Completer

type Config

type Config struct {
	TargetDir string // Directory where executables will be installed (default: ~/.local/bin)
	TempDir   string // Directory for temporary files (default: system temp)
}

Config holds configuration for the installer

type DownloadLinks struct {
	ArchiveUrl string
}

DownloadLinks holds URLs for downloading assets and checksums

type GitHubAsset

type GitHubAsset struct {
	Name        string `json:"name"`
	DownloadURL string `json:"browser_download_url"`
}

GitHubAsset represents an individual asset in a release

type GitHubRelease

type GitHubRelease struct {
	TagName string        `json:"tag_name"`
	Assets  []GitHubAsset `json:"assets"`
}

GitHubRelease holds release information fetched from the GitHub API

type Installer

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

Installer manages installation of repositories

func NewInstaller

func NewInstaller(config Config, repoUrls []string) (*Installer, error)

func (*Installer) Download

func (i *Installer) Download(downloadURL, destDir string) (string, error)

func (*Installer) ExtractTarGz

func (i *Installer) ExtractTarGz(gzipStream io.Reader, extractDir string) ([]string, error)

func (*Installer) Install

func (i *Installer) Install() error

type Repo

type Repo struct {
	Owner   string
	Name    string
	Version string
	Links   DownloadLinks
}

func NewRepo

func NewRepo(repoUrl string) (*Repo, error)

type SnipScanner

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

func NewSnipScanner

func NewSnipScanner(r io.Reader) *SnipScanner

func (*SnipScanner) Err

func (s *SnipScanner) Err() error

func (*SnipScanner) Scan

func (s *SnipScanner) Scan() bool

func (*SnipScanner) Snippet

func (s *SnipScanner) Snippet() Snippet

type Snippet

type Snippet struct {
	Lang    string
	Name    string
	Content bytes.Buffer
}

func GetSnippet

func GetSnippet(r io.Reader) (*Snippet, error)

func (*Snippet) PrintSnippet

func (s *Snippet) PrintSnippet()

Jump to

Keyboard shortcuts

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