source

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package source parses, normalizes, and classifies skill source references (git shorthand, full HTTPS/SSH, local path, url) into a canonical identity.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalidSource = errors.New("invalid source")

ErrInvalidSource is returned when a source argument cannot be parsed.

Functions

This section is empty.

Types

type Ref

type Ref struct {
	Type      Type
	Original  string
	URL       string
	Owner     string
	Repo      string
	Path      string
	LocalPath string
}

Ref is a parsed, normalized source reference.

func Parse

func Parse(raw string) (Ref, error)

Parse classifies and normalizes a raw source argument.

Example
package main

import (
	"fmt"

	"github.com/glapsfun/gskill/internal/source"
)

func main() {
	ref, _ := source.Parse("github.com/acme/widgets/my-skill")
	fmt.Println(ref.Type, ref.Owner, ref.Repo, ref.Path)
	fmt.Println(ref.URL)
}
Output:
git acme widgets my-skill
https://github.com/acme/widgets.git

func (Ref) Display added in v0.3.0

func (s Ref) Display() string

Display returns a short human name for progress lines: owner/repo when known, else the repo name (local-promoted git repos have no owner), else the canonical identity (never the raw URL, which may carry credentials). For git identities the empty host/owner segments are trimmed so a bare-URL ref renders as its host, not "host//"; local paths pass through untouched.

func (Ref) Identity

func (s Ref) Identity() string

Identity returns the canonical identity string for the reference: the local path for local sources, or host/owner/repo[/path] for git sources.

type Repo added in v0.11.0

type Repo struct {
	Kind RepoKind
	// Key is what grouping and --repo matching compare.
	Key string
	// Label is shown to people, written to JSON, and accepted back by --repo.
	Label string
}

Repo is the repository a source belongs to, for grouping and selecting skills by repository (spec 032 FR-001 to FR-003). It exists next to Identity because grouping must drop the in-repository path and compare hosts the way they compare names: case-insensitively, and owner and repo case-insensitively only on the known hosts.

func ParseRepo added in v0.11.0

func ParseRepo(raw, root string) (Repo, error)

ParseRepo parses a --repo value. It accepts every spelling Parse accepts for a repository and rejects one that names a path inside it with a *RepoPathError; other parse errors are returned unchanged.

func RepoOf added in v0.11.0

func RepoOf(ref Ref, root string) Repo

RepoOf returns the repository identity of a parsed, unpromoted reference. Relative local paths resolve against root, the project root.

func (Repo) Equal added in v0.11.0

func (r Repo) Equal(o Repo) bool

Equal reports whether two identities name the same repository. Labels are never compared.

type RepoKind added in v0.11.0

type RepoKind string

RepoKind classifies a repository identity.

const (
	RepoRemote  RepoKind = "remote"
	RepoLocal   RepoKind = "local"
	RepoInvalid RepoKind = "invalid"
)

Repository identity kinds.

type RepoPathError added in v0.11.0

type RepoPathError struct {
	// Value is the raw --repo value.
	Value string
	// Repo is the label of the repository the value points into.
	Repo string
}

RepoPathError reports a --repo value that names a path inside a repository instead of the repository itself.

func (*RepoPathError) Error added in v0.11.0

func (e *RepoPathError) Error() string

type Type

type Type string

Type classifies where a skill comes from, as recorded in the lockfile.

const (
	TypeGit   Type = "git"
	TypeLocal Type = "local"
	TypeURL   Type = "url"
)

Source types (FR-007, FR-008).

func (Type) Valid

func (t Type) Valid() bool

Valid reports whether t is a recognized source type.

Jump to

Keyboard shortcuts

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