pathmeta

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HookCurTmpPath = "__VFOX_CURTMPPATH"

	ReadWriteAuth = 0755 // can write and read
)

Variables

View Source
var ConfigFileNames = []string{
	".vfox.toml",
	"vfox.toml",
}

ConfigFileNames defines the config file names and their priority

Functions

func DetermineConfigPath

func DetermineConfigPath(dir string) string

DetermineConfigPath determines the default path for the config file Used for path inference when saving new configs

func IsVfoxRelatedPath

func IsVfoxRelatedPath(path string) bool

IsVfoxRelatedPath checks if the given path is related to vfox

Types

type Attr

type Attr map[string]string

Attr is a type alias for map[string]string, used for tool attributes

type FileRecord

type FileRecord struct {
	Record map[string]string
	Path   string
	// contains filtered or unexported fields
}

FileRecord is a file that contains a map of string to string

func NewFileRecord

func NewFileRecord(path string) (*FileRecord, error)

NewFileRecord creates a new FileRecord from a file if the file does not exist, an empty FileRecord is returned

func (*FileRecord) Save

func (m *FileRecord) Save() error

type PathMeta

type PathMeta struct {
	User       UserPaths
	Shared     SharedPaths
	Working    WorkingPaths
	Executable string // Executable path
}

func NewPathMeta

func NewPathMeta(userHome, sharedRoot, currentDir string, pid int) (*PathMeta, error)

NewPathMeta creates a new PathMeta instance based on the provided parameters and environment variables. If not provide sharedRoot, it will use userHome as sharedRoot.

func (*PathMeta) ApplyStoragePath added in v1.0.2

func (p *PathMeta) ApplyStoragePath(storagePath string) error

ApplyStoragePath applies the storage path from config to update the Installs path If storagePath is empty, the current Installs path is unchanged

type SharedPaths

type SharedPaths struct {
	Root     string // /opt/vfox or C:\Program Files\vfox (from VFOX_ROOT or default)
	Installs string // ${SharedRoot}/installs (SDK unique install location)
	Plugins  string // ${SharedRoot}/plugins (plugins)
	Config   string // ${SharedRoot}/config.yaml (global config)
}

type ToolConfig

type ToolConfig struct {
	Version string
	Attr    Attr // Additional attributes (e.g., vendor, dist)
}

ToolConfig represents a tool configuration with version and optional attributes Supports two formats: 1. Simple: nodejs = "21.5.1" 2. Complex: java = { version = "21", vendor = "openjdk" }

func (*ToolConfig) MarshalInline

func (t *ToolConfig) MarshalInline() string

MarshalInline serializes the tool configuration to an inline TOML value Returns just the value part (without the key), e.g.:

  • "21.5.1" (for simple format)
  • {version = "21", vendor = "openjdk"} (for complex format)

func (*ToolConfig) UnmarshalTOML

func (t *ToolConfig) UnmarshalTOML(data interface{}) error

UnmarshalTOML custom unmarshaling to support both simple and complex formats

type ToolVersions

type ToolVersions map[string]string

ToolVersions is a type alias for map of tool name to version

type Tools

type Tools map[string]*ToolConfig

Tools is a map of tool name to tool configuration

func (*Tools) Get

func (t *Tools) Get(name string) (*ToolConfig, bool)

Get retrieves a tool configuration

func (*Tools) GetVersion

func (t *Tools) GetVersion(name string) (string, bool)

GetVersion retrieves only the version of a tool

func (*Tools) Len

func (t *Tools) Len() int

Len returns the number of tools

func (*Tools) List

func (t *Tools) List() ToolVersions

List returns all tools as a map of name -> version

func (*Tools) MarshalTOML

func (t *Tools) MarshalTOML() ([]byte, error)

MarshalTOML implements the toml.Marshaler interface

func (*Tools) Remove

func (t *Tools) Remove(name string)

Remove removes a tool from the collection

func (*Tools) Set

func (t *Tools) Set(name, version string)

Set adds or updates a tool configuration (simple version only)

func (*Tools) SetWithAttr

func (t *Tools) SetWithAttr(name, version string, attr Attr)

SetWithAttr adds or updates a tool configuration with attributes

func (*Tools) SortedKeys

func (t *Tools) SortedKeys() []string

SortedKeys returns a sorted list of tool names

func (*Tools) UnmarshalTOML

func (t *Tools) UnmarshalTOML(data interface{}) error

UnmarshalTOML implements the toml.Unmarshaler interface

type UserPaths

type UserPaths struct {
	Home   string // ~/.vfox
	Temp   string // ~/.vfox/tmp (session temporary)
	Config string // ~/.vfox/config.yaml (user override config)
}

type VfoxToml

type VfoxToml struct {
	Tools Tools  `toml:"tools"`
	Path  string // Config file path (empty for new configs)
}

VfoxToml represents the vfox.toml configuration file Example:

[tools]
nodejs = "21.5.1"
java = { version = "21", vendor = "openjdk" }

func LoadConfig

func LoadConfig(dir string) (*VfoxToml, error)

LoadConfig loads the config file from the specified directory Priority: .vfox.toml > vfox.toml > .tool-versions If .tool-versions is read, it will be automatically saved as .vfox.toml (without deleting the original file) pathmeta is not aware of scope, the caller should set it

func LoadVfoxToml

func LoadVfoxToml(path string) (*VfoxToml, error)

LoadVfoxToml loads vfox.toml from the specified path Returns an empty VfoxToml if the file doesn't exist

func NewVfoxToml

func NewVfoxToml() *VfoxToml

NewVfoxToml creates a new empty VfoxToml instance

func (*VfoxToml) GetAllTools

func (v *VfoxToml) GetAllTools() ToolVersions

GetAllTools returns all tools as a ToolVersions map (name -> version)

func (*VfoxToml) GetToolConfig

func (v *VfoxToml) GetToolConfig(name string) (*ToolConfig, bool)

GetToolConfig retrieves the complete tool configuration (including attributes)

func (*VfoxToml) GetToolVersion

func (v *VfoxToml) GetToolVersion(name string) (string, bool)

GetToolVersion retrieves only the version of a tool

func (*VfoxToml) IsEmpty

func (v *VfoxToml) IsEmpty() bool

IsEmpty checks if the config has no tools

func (*VfoxToml) IsNew

func (v *VfoxToml) IsNew() bool

IsNew checks if this is a new config (never saved before)

func (*VfoxToml) MarshalTOML

func (v *VfoxToml) MarshalTOML() ([]byte, error)

MarshalTOML serializes the configuration to TOML format

func (*VfoxToml) RemoveTool

func (v *VfoxToml) RemoveTool(name string)

RemoveTool removes a tool from the configuration

func (*VfoxToml) Save

func (v *VfoxToml) Save() error

Save saves the config to the recorded Path Returns error if Path is empty or config is empty

func (*VfoxToml) SaveTo

func (v *VfoxToml) SaveTo(dir string) error

SaveTo saves the config to the specified directory (auto-selects filename) Prefers .vfox.toml, uses vfox.toml if it already exists Does not create a file if the config is empty

func (*VfoxToml) SaveToPath

func (v *VfoxToml) SaveToPath(path string) error

SaveToPath saves the config to the specified full path If the config is empty:

  • If file doesn't exist: do nothing (don't create file)
  • If file exists: update it with empty [tools] section

func (*VfoxToml) SetTool

func (v *VfoxToml) SetTool(name, version string)

SetTool sets or updates a tool configuration (simple version only)

func (*VfoxToml) SetToolWithAttr

func (v *VfoxToml) SetToolWithAttr(name, version string, attr Attr)

SetToolWithAttr sets or updates a tool configuration with attributes

type WorkingPaths

type WorkingPaths struct {
	Directory     string // Current working directory
	ProjectSdkDir string // .vfox/sdk (project-level)
	SessionSdkDir string // Session temporary shim path
	GlobalSdkDir  string // Global shim path in user home
}

Jump to

Keyboard shortcuts

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