gdshpkg

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 16 Imported by: 3 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gdsh-pkg

Installs gdsh command packages into a command root (<root>/packages/<name>) from the reviewed index godot-gdsh-lib-manifest. It is shared by the gdsh CLI (gdsh package install) and mcp-sh-godot (mcp_sh_godot gdsh package install). It has no dependencies outside the standard library.

c := &gdshpkg.Client{}                   // published index, cached for a day
idx, _ := c.FetchIndex(ctx, false)
steps, _ := idx.Plan(root, []string{"terrain3d"}, false) // level first, as a sibling
err := c.Install(ctx, root, steps, func(line string) { fmt.Println(line) })
  • Installs download the commit the index pins (archive/<commit>.zip), not the tag, so a moved tag can't change what is served.
  • The archive's wrapper folder, dot files and _export_ignore/ are dropped. The package is unpacked under <root>/.pkg-staging and renamed into place, so a failed install leaves the old copy untouched.
  • A package with non-gdsh requires (project_only) is refused, since a command root can't hold that code. Install it into the project with gdaddon.
  • GDSH_PACKAGE_INDEX overrides the index: a URL, or a local manifest.json.

cmd/gdsh-manifest (check, pin, propose) maintains the index; see its --help and the manifest repo's README.

Documentation

Overview

Package gdshpkg installs gdsh command packages into a command root (<root>/packages/<name>) from a reviewed index: godot-gdsh-lib-manifest. Each entry pins a tag and the commit it was reviewed at; installs download that commit, so a moved tag can't change what is served.

Index

Constants

View Source
const DefaultManifestURL = "https://raw.githubusercontent.com/brohd11/godot-gdsh-lib-manifest/main/manifest.json"

DefaultManifestURL is the published index.

View Source
const GdshRepo = "brohd11/godot-gdsh"

GdshRepo is gdsh itself. Hosts bring their own copy, so it is never installed.

View Source
const IndexEnv = "GDSH_PACKAGE_INDEX"

IndexEnv overrides the index location: a URL, or a local manifest.json (read as is, not cached), for trying an index before publishing it.

Variables

This section is empty.

Functions

func CompareVersions

func CompareVersions(a, b string) int

CompareVersions orders "v1.2.3"-style versions: -1, 0 or 1. A leading v is ignored, numeric parts compare as numbers, and a missing part counts as 0.

func Dependents

func Dependents(installed []Installed, name string, m *Manifest) []string

Dependents returns the installed packages that require name. Requires are matched by repo through the index when it is given, else by the repo's last path part.

func Extract

func Extract(data []byte, dir string) error

Extract unpacks a repo zip into dir: the single wrapper folder GitHub adds is dropped, and so are dot files/folders and export_ignore folders at any depth. Links and paths escaping dir are refused.

func PackagesDir

func PackagesDir(root string) string

PackagesDir is where a root keeps its packages.

func Remove

func Remove(root, name string) error

Remove deletes an installed package's folder.

func SplitRequire

func SplitRequire(spec string) (repo, tag string)

SplitRequire splits "owner/repo@tag" (a github.com/ prefix or .git suffix is allowed).

Types

type Action

type Action string

Action is what a plan does with one package.

const (
	ActInstall Action = "install"
	ActUpdate  Action = "update"
	ActKeep    Action = "keep" // installed at the pin or newer
)

type Cfg

type Cfg struct {
	Name    string
	Version string
	Path    string   // project path, e.g. addons/_lib/gdsh_lib/level; its basename is the install name
	Require []string // "owner/repo@tag"
}

Cfg is the [package] section of a package's package.cfg.

func ParseCfg

func ParseCfg(data []byte) (Cfg, error)

ParseCfg reads the [package] section of a Godot ConfigFile: quoted strings and string arrays, which may span lines. Other sections and value types are ignored.

func (Cfg) InstallName

func (c Cfg) InstallName() string

InstallName is the folder a package installs to: the basename of its path. Packages find their dependencies as sibling folders by this name.

type Client

type Client struct {
	HTTP        *http.Client
	ManifestURL string
	// ArchiveURL is a zip of repo at commit; default GitHub's codeload archive.
	ArchiveURL func(repo, commit string) string
	// CacheDir holds manifest.json; default <user cache>/gdsh.
	CacheDir string
	TTL      time.Duration
}

Client fetches the index and package archives. The zero value uses the published index and GitHub, caching the index under the user cache folder for a day.

func (*Client) Archive

func (c *Client) Archive(ctx context.Context, repo, commit string) ([]byte, error)

Archive downloads repo at commit as a zip.

func (*Client) FetchIndex

func (c *Client) FetchIndex(ctx context.Context, refresh bool) (*Index, error)

FetchIndex returns the index: the cached copy while it is younger than TTL (unless refresh), else a fresh download, else the cached copy marked Stale. A local file is always read fresh.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get downloads url (at most 64 MiB), failing on any status but 200.

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

HTTPClient is the client requests go through.

func (*Client) IndexURL

func (c *Client) IndexURL() string

IndexURL is where the index comes from: ManifestURL, else $GDSH_PACKAGE_INDEX, else the published one.

func (*Client) Install

func (c *Client) Install(ctx context.Context, root string, steps []Step, report func(string)) error

Install downloads and places every step that isn't ActKeep. report gets one line per package and any warnings. Each package is unpacked beside the root and swapped in with a rename, so a failure leaves the installed copy as it was.

type Index

type Index struct {
	*Manifest
	Stale   bool
	Fetched time.Time
}

Index is a fetched manifest. Stale is set when the network failed and the cached copy was used.

type Installed

type Installed struct {
	Name string // its folder
	Dir  string
	Cfg  Cfg
}

Installed is a package found in a root.

func ListInstalled

func ListInstalled(root string) ([]Installed, error)

ListInstalled returns the packages in root, by name: folders under packages/ that have a package.cfg. A root without packages/ has none.

type Manifest

type Manifest struct {
	Version  int       `json:"version"`
	Packages []Package `json:"packages"`
}

Manifest is the index: packages approved for install.

func LoadManifest

func LoadManifest(path string) (*Manifest, error)

LoadManifest reads an index file.

func ParseManifest

func ParseManifest(data []byte) (*Manifest, error)

ParseManifest decodes and sanity-checks an index.

func (*Manifest) Find

func (m *Manifest) Find(nameOrRepo string) (*Package, bool)

Find returns the entry named name, or by its repo ("owner/repo").

func (*Manifest) Marshal

func (m *Manifest) Marshal() ([]byte, error)

Marshal is the canonical file form: two-space indent and a trailing newline.

func (*Manifest) Outdated

func (m *Manifest) Outdated(installed []Installed) []Update

Outdated compares installed versions with the index pins. Packages not in the index are skipped.

func (*Manifest) Plan

func (m *Manifest) Plan(root string, names []string, force bool) ([]Step, error)

Plan resolves names (index names or repos) and their requires against what root has. With force, installed packages are reinstalled at their pin even when current. No network.

func (*Manifest) Search

func (m *Manifest) Search(term string) []Package

Search returns entries whose name, summary or tags contain term (all for "").

type Package

type Package struct {
	Name    string   `json:"name"`
	Repo    string   `json:"repo"`
	Summary string   `json:"summary"`
	Tags    []string `json:"tags,omitempty"`
	Tag     string   `json:"tag"`
	Commit  string   `json:"commit"`
	// Gdsh is the lowest gdsh version the package requires.
	Gdsh string `json:"gdsh,omitempty"`
	// Requires are other indexed gdsh packages (repos), installed as siblings.
	Requires []string `json:"requires"`
	// ProjectOnly are requires a command root can't hold (non-gdsh code such as util_r): the
	// package has to be installed into the project instead, with gdaddon.
	ProjectOnly []string `json:"project_only,omitempty"`
}

Package is one entry. Name, Repo, Summary, Tags and the Tag/Commit pin are written by hand; Gdsh, Requires and ProjectOnly are derived from package.cfg at Commit by gdsh-manifest.

type ProjectOnlyError

type ProjectOnlyError struct{ Pkg Package }

ProjectOnlyError is a package a command root can't hold.

func (ProjectOnlyError) Error

func (e ProjectOnlyError) Error() string

type Step

type Step struct {
	Pkg       Package
	Action    Action
	Installed string // the installed version, if any
	For       string // the package that pulled it in; "" when asked for
}

Step is one package of a plan, dependencies before the packages that need them.

type Update

type Update struct {
	Installed
	Pkg Package
}

Update is an installed package with a newer pin in the index.

Directories

Path Synopsis
cmd
gdsh-manifest command
gdsh-manifest maintains godot-gdsh-lib-manifest's manifest.json.
gdsh-manifest maintains godot-gdsh-lib-manifest's manifest.json.
Package maint keeps godot-gdsh-lib-manifest honest: it derives each entry's gdsh, requires and project_only from package.cfg at the pinned commit, checks the pin and the package shape, moves pins (Pin) and lists newer tags for review (Propose).
Package maint keeps godot-gdsh-lib-manifest honest: it derives each entry's gdsh, requires and project_only from package.cfg at the pinned commit, checks the pin and the package shape, moves pins (Pin) and lists newer tags for review (Propose).

Jump to

Keyboard shortcuts

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