binnames

package
v0.162.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: BSD-3-Clause Imports: 22 Imported by: 0 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.

Documentation

Overview

Package binnames answers one question about a Go repository: what will `go install` call each of its commands, and does a well-known command already own that name?

⛔ WHY IT EXISTS. go-authn/kinit v0.1.0 had its main.go at the MODULE ROOT, so `go install github.com/go-authn/kinit@latest` built `kinit` (`kinit.exe` on Windows) and put it on the PATH of anyone who ran it, in front of or behind MIT krb5's, Heimdal's and MIT Kerberos for Windows' own `kinit`. The README said `authn-kinit`; the README was not what `go install` reads. The name of an installed binary is decided by the import path, so it is a property of the layout and nothing in a test or a review looks at it.

Index

Constants

This section is empty.

Variables

View Source
var ErrCap = errors.New("REST call cap reached")

ErrCap means the sweep reached its own ceiling.

Functions

func HTTPRaw

func HTTPRaw(token string) func(string) ([]byte, error)

HTTPRaw is the default Raw: an HTTP GET with an optional token, and a non-200 is an error, never an empty file.

func InstallName

func InstallName(importPath string) string

InstallName is the name `go install` gives the package at importPath.

It is the last element, except that a major-version element is skipped: example.com/mycmd/v2 installs as mycmd, not as v2 (cmd/go DefaultExecName, golang.org/issue/24667). A path that is nothing but a version element keeps it.

func Normalise

func Normalise(name string) string

Normalise folds a command name for comparison: lower case, no `.exe`. Windows resolves `Kinit.EXE` and `kinit` to the same command.

func RemoteCandidate

func RemoteCandidate(dir string, files []string) bool

RemoteCandidate is the directory filter a remote scan uses: the root, any directory holding a main.go, and anything under cmd/. A `package main` in a differently named file elsewhere is not seen, and the report says so.

func Scan

func Scan(t Tree, opt Options) ([]Main, []Unread, error)

Scan lists the `package main` directories of a tree.

Types

type Budget

type Budget struct {
	Cap  int
	Used int
	// contains filtered or unexported fields
}

Budget counts the REST calls a sweep makes and refuses past a cap.

⛔ The cap exists because sweeps starve Renovate: the hourly REST budget is per user, and a fleet sweep and the scheduled Renovate runs draw on the same 5000. This is a ceiling on THIS command, in addition to the shared guard in package fleet, which only stops at a reserve.

func (*Budget) Spend

func (b *Budget) Spend(n int) error

Spend charges n calls, or refuses without charging.

type Collision

type Collision struct {
	Binary string
	Owners []Ref
}

A Collision is an installed name that something else already owns.

func (Collision) Describe

func (c Collision) Describe() string

Describe renders what owns a name, preferring the committed lists, which cite a source, and saying when only the host's PATH knows it.

type DirTree

type DirTree struct{ Root string }

DirTree reads a working tree as it is on disk.

func (DirTree) Files

func (d DirTree) Files() ([]string, error)

func (DirTree) Read

func (d DirTree) Read(p string) ([]byte, error)

type GitTree

type GitTree struct {
	Dir string
	Ref string
}

GitTree reads a repository at a ref WITHOUT checking it out.

⛔ A clone on this machine is usually sitting on somebody's branch, and a working-tree scan of it reports that branch, not what `go install ...@latest` would build. Reading origin's default branch from the object database answers the question that was asked, and touches nothing: no checkout, no index.

func (GitTree) Files

func (g GitTree) Files() ([]string, error)

func (GitTree) Read

func (g GitTree) Read(p string) ([]byte, error)

type Index

type Index map[string][]Ref

Index maps a normalised command name to everything that owns it.

func LoadRefs

func LoadRefs() (Index, error)

LoadRefs reads the committed lists.

func (Index) Check

func (idx Index) Check(name string, allow map[string]bool) (Collision, bool)

Check compares an install name with the index.

func (Index) PathSupplement

func (idx Index) PathSupplement(pathEnv string, skip map[string]bool) (read []string, failed []Unread)

PathSupplement adds the executables found on a PATH to the index, as a supplement to the committed lists. Directories in skip are not read: they hold the fleet's own installed tools, which would otherwise collide with themselves. It returns the directories it read and the ones it could not.

type Main

type Main struct {
	// Dir is the slash-separated directory inside the repository, "" for the root.
	Dir string
	// Import is the import path `go install` is given.
	Import string
	// Name is what the build writes, without the `.exe` Windows adds.
	Name string
	// Note says when Name is a guess, for example a repository with no go.mod.
	Note string
}

A Main is one `package main` and the name `go install` gives it.

type Options

type Options struct {
	// RepoName is the last element of the repository, used to name a main at
	// the root of a tree that has no go.mod (the GOPATH-era layout).
	RepoName string
	// Candidate, when set, limits which directories are opened. A remote scan
	// has to pay a request per directory and sets it; a local one leaves it nil.
	Candidate func(dir string, files []string) bool
}

Options narrow a scan.

type Ref

type Ref struct {
	Name    string // as the source spells it
	List    string
	Source  string
	Detail  string
	Host    bool // from the host's PATH, not from a committed list
	Fetched string
}

A Ref is one well-known command.

type Remote

type Remote struct {
	Repo   string // owner/name
	Branch string
	Budget *Budget
	// API runs `gh api` style requests; Raw fetches a URL. Tests replace both.
	API func(args ...string) ([]byte, error)
	Raw func(url string) ([]byte, error)
}

Remote reads a repository from GitHub: ONE recursive git-trees API call for the file list, then raw file contents, which are not REST API calls and do not draw on the hourly budget.

func (*Remote) Files

func (r *Remote) Files() ([]string, error)

func (*Remote) Read

func (r *Remote) Read(p string) ([]byte, error)

type Tree

type Tree interface {
	// Files lists every file, slash-separated, relative to the root.
	Files() ([]string, error)
	// Read returns one file's bytes.
	Read(path string) ([]byte, error)
}

A Tree is the files of one repository at one instant, wherever they live: a working tree, a ref read through git, or a GitHub tree read over the API.

type Unread

type Unread struct {
	What string
	Why  string
}

Unread is something the scan could not read. It is never a clean answer: a repository with an Unread entry has NOT been judged.

func (Unread) String

func (u Unread) String() string

Directories

Path Synopsis
Package main regenerates internal/binnames/ref/*.txt from the sources it names.
Package main regenerates internal/binnames/ref/*.txt from the sources it names.

Jump to

Keyboard shortcuts

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