config

package
v0.1.2-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package config defines drift's configuration types and loading logic.

Config resolution order:

  1. ~/.config/drift/config.toml (global hosts)
  2. .drift/config.toml (project hosts + mappings, walked up from cwd)

Project config hosts with the same name override global hosts. Env vars in auth fields ($VAR) are expanded at connection time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteGlobalHost

func DeleteGlobalHost(cfg *MergedConfig, name string) error

DeleteGlobalHost removes a host by name from the global config file.

func DeleteProjectHost

func DeleteProjectHost(cfg *MergedConfig, name string) error

DeleteProjectHost removes a host by name from the project config file.

func SaveGlobalHost

func SaveGlobalHost(cfg *MergedConfig, h Host, oldName string) error

SaveGlobalHost adds or replaces a host in the global config file. If oldName != "" the host with that name is replaced; otherwise a new host is appended.

func SaveProjectHost

func SaveProjectHost(cfg *MergedConfig, h Host, oldName string) error

SaveProjectHost adds or replaces a host in the project config file.

Types

type Auth

type Auth struct {
	Type       string `toml:"type"`       // "password" | "keyfile" | "agent"
	Password   string `toml:"password"`   // supports $ENV_VAR references
	KeyFile    string `toml:"key_file"`   // path, ~ expanded at connect time
	Passphrase string `toml:"passphrase"` // supports $ENV_VAR references
}

Auth configures how to authenticate with a Host.

type Defaults

type Defaults struct {
	Port int    `toml:"port"` // default 22
	User string `toml:"user"`
}

Defaults provides fallback values for hosts that omit optional fields.

type GlobalConfig

type GlobalConfig struct {
	Defaults Defaults `toml:"defaults"`
	Hosts    []Host   `toml:"hosts"`
}

GlobalConfig is the structure of ~/.config/drift/config.toml.

type Host

type Host struct {
	Name     string    `toml:"name"`     // unique identifier, e.g. "prod"
	Hostname string    `toml:"hostname"` // IP or domain
	Port     int       `toml:"port"`     // default: 22 (sftp) or 21 (ftp)
	User     string    `toml:"user"`
	Auth     Auth      `toml:"auth"`
	RootPath string    `toml:"root_path"`          // remote base directory
	Protocol string    `toml:"protocol"`           // "sftp" (default), "ftp", or "ftps" (FTP over explicit TLS)
	Mappings []Mapping `toml:"mappings,omitempty"` // per-host path mappings
}

Host represents a remote SFTP/SSH or FTP target.

func SortedHostsByName

func SortedHostsByName(hosts []Host) []Host

SortedHostsByName returns a copy of hosts sorted by name and hostname.

type HostScope

type HostScope int

HostScope indicates whether a host was defined globally or in a project config.

const (
	ScopeGlobal HostScope = iota
	ScopeProject
)

type Mapping

type Mapping struct {
	Local  string `toml:"local"`  // relative to project root
	Remote string `toml:"remote"` // relative to Host.RootPath
}

Mapping maps a local directory/file to a remote path.

type MergedConfig

type MergedConfig struct {
	GlobalDefaults  Defaults
	ProjectDefaults Defaults
	GlobalHosts     []Host          // hosts from ~/.config/drift/config.toml
	ProjectHosts    []Host          // hosts from .drift/config.toml
	Hosts           map[string]Host // merged view: project overrides global, keyed by Name
	Mappings        []Mapping
	ProjectRoot     string // absolute path of the directory containing .drift/
}

MergedConfig is the runtime-resolved configuration after merging global and project configs.

func Load

func Load(startDir string) (*MergedConfig, error)

Load finds and merges global and project configs relative to startDir. startDir is typically os.Getwd().

type ProjectConfig

type ProjectConfig struct {
	Defaults Defaults  `toml:"defaults"`
	Hosts    []Host    `toml:"hosts"`
	Mappings []Mapping `toml:"mappings"`
}

ProjectConfig is the structure of .drift/config.toml.

Jump to

Keyboard shortcuts

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