Documentation
¶
Overview ¶
Package appctx provides application path resolution for repository-backed CLI applications.
AppPaths holds the repository root and platform-scoped paths for config, data, state, and cache directories. NewAppPaths fills missing roots using the user's platform defaults (XDG on Unix, APPDATA on Windows). NewGitAppPaths auto-detects the git repository root via FindGitRoot which tries the git CLI first and falls back to upward filesystem scanning.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindGitRoot ¶
FindGitRoot findGitRoot attempts to use the git CLI to determine the repository top-level directory starting from 'start'. If that fails (git not available, not a git worktree, or command error), it falls back to the original upward filesystem search for a .git entry.
Types ¶
type AppPaths ¶ added in v1.2.0
type AppPaths struct {
Appname string
// Root is the path to the root of the context.
Root string
// configRoot is the base directory for user configuration files.
ConfigRoot string
// stateRoot holds transient state files for the context.
StateRoot string
// dataRoot is for programmatically managed data shipped with the program.
DataRoot string
// cacheRoot is for cache artifacts.
CacheRoot string
// localConfigRoot is the repo-local override location
LocalConfigRoot string
}
AppPaths holds paths and configuration roots for a repository-backed app context. Root is the repository root. Other roots default to platform user-scoped locations when not provided.
func NewAppPaths ¶ added in v1.2.0
NewAppPaths constructs app paths and fills missing roots using platform defaults derived from the provided context.
Behavior:
- If an option sets a value it is used as-is.
- If Root is not set it is inferred from Runtime.Getwd().
- ConfigRoot, DataRoot, StateRoot, and CacheRoot use the corresponding user-scoped platform paths and are joined with DefaultAppName.