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 ¶
- Variables
- func HTTPRaw(token string) func(string) ([]byte, error)
- func InstallName(importPath string) string
- func Normalise(name string) string
- func RemoteCandidate(dir string, files []string) bool
- func Scan(t Tree, opt Options) ([]Main, []Unread, error)
- type Budget
- type Collision
- type DirTree
- type GitTree
- type Index
- type Main
- type Options
- type Ref
- type Remote
- type Tree
- type Unread
Constants ¶
This section is empty.
Variables ¶
var ErrCap = errors.New("REST call cap reached")
ErrCap means the sweep reached its own ceiling.
Functions ¶
func HTTPRaw ¶
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 ¶
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 ¶
Normalise folds a command name for comparison: lower case, no `.exe`. Windows resolves `Kinit.EXE` and `kinit` to the same command.
func RemoteCandidate ¶
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.
Types ¶
type Budget ¶
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.
type GitTree ¶
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.
type Index ¶
Index maps a normalised command name to everything that owns it.
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.
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.