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 ¶
var TOOLBOX = []string{
"cli/cli",
"mikefarah/yq",
"junegunn/fzf",
}
Functions ¶
func ChoseSnippet ¶
Types ¶
type Completer ¶
type Completer struct {
// contains filtered or unexported fields
}
func NewCompleter ¶
func (*Completer) SetOutputDir ¶
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 ¶
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 (*Installer) ExtractTarGz ¶
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