configpath

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package configpath resolves one config file path for configbind. Candidates are searched exclusively in priority order: explicit path, extra read paths, user config, then system config.

Index

Constants

View Source
const ProcessKey = "config-path"

ProcessKey is the stable process-level key for the --config-path value in cliparser results. It is not a Bind-prefix overlay key.

Variables

This section is empty.

Functions

func ConfigPathDef

func ConfigPathDef() cliparser.Def

ConfigPathDef returns the process-level cliparser definition for --config-path. ConfigKey is ProcessKey ("config-path"), not a Bind-prefix field key.

func ExplicitPathFromParse

func ExplicitPathFromParse(res cliparser.Result) string

ExplicitPathFromParse extracts the --config-path value from a cliparser.Result, if set.

func Resolve

func Resolve(vendor, tool, fileName, explicitPath string) (path string, found bool, err error)

Resolve chooses one config file path.

If explicitPath is non-empty, that path is the only candidate: missing or unreadable returns an error (no directory search fallback). On success found is true.

With no explicit path or extras, vendor, tool, and fileName are required; directory search prefers user over system and returns at most one path. When neither has the file, found is false and err is nil (TOML may be skipped).

func ResolveWithExtras added in v0.1.12

func ResolveWithExtras(vendor, tool, fileName, explicitPath string, extraReadPaths []string) (path string, found bool, err error)

ResolveWithExtras chooses the first readable config file from explicitPath, extraReadPaths in slice order, then the user/system config directory search. Missing or unreadable extra paths are skipped. An explicit path remains strict: when supplied but unreadable, resolution fails without fallback.

func ResolveWithExtrasAndSearch added in v0.1.12

func ResolveWithExtrasAndSearch(vendor, tool, fileName, explicitPath string, extraReadPaths []string, search FileSearch) (path string, found bool, err error)

ResolveWithExtrasAndSearch is like ResolveWithExtras but injects the user/system directory search implementation.

func ResolveWithSearch

func ResolveWithSearch(vendor, tool, fileName, explicitPath string, search FileSearch) (path string, found bool, err error)

ResolveWithSearch is like Resolve but uses the provided FileSearch for directory lookup.

Types

type ConfigDirSearch

type ConfigDirSearch struct{}

ConfigDirSearch uses github.com/shibukawa/configdir (user then system, exclusive).

func (ConfigDirSearch) Find

func (ConfigDirSearch) Find(vendor, tool, fileName string) (string, bool)

Find implements FileSearch using configdir.QueryFolderContainsFile.

type FileSearch

type FileSearch interface {
	// Find returns the full path to fileName if present under vendor/tool layout.
	Find(vendor, tool, fileName string) (fullPath string, found bool)
}

FileSearch finds a config file under vendor/tool directories (user first, then system). Production uses ConfigDirSearch; tests may inject fixed roots.

type FixedRootsSearch

type FixedRootsSearch struct {
	UserRoot   string
	SystemRoot string
}

FixedRootsSearch searches userRoot then systemRoot with vendor/tool segments (for tests).

func (FixedRootsSearch) Find

func (s FixedRootsSearch) Find(vendor, tool, fileName string) (string, bool)

Find implements FileSearch with explicit roots, user preferred over system.

Jump to

Keyboard shortcuts

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