config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvOutputDir = "TRANSCRIPT_OUTPUT_DIR"
)

Environment variable fallbacks.

View Source
const (
	KeyOutputDir = "output-dir"
)

Config keys.

Variables

View Source
var (
	// ErrInvalidSyntax is returned when the config file has invalid syntax.
	ErrInvalidSyntax = errors.New("invalid config syntax")
	// ErrInvalidKey is returned when a config key contains invalid characters.
	ErrInvalidKey = errors.New("invalid config key")
	// ErrNotWritable is returned when a directory is not writable.
	ErrNotWritable = errors.New("directory not writable")
	// ErrNotDirectory is returned when a path is not a directory.
	ErrNotDirectory = errors.New("path is not a directory")
)

Sentinel errors for error handling with errors.Is().

Functions

func EnsureExtension added in v0.4.0

func EnsureExtension(path, ext string) string

EnsureExtension adds ext to path if path has no extension. If path already has an extension (including hidden files like ".bashrc"), it is returned unchanged.

Examples:

EnsureExtension("notes", ".md")           → "notes.md"
EnsureExtension("notes.md", ".md")        → "notes.md"
EnsureExtension("notes.txt", ".md")       → "notes.txt"
EnsureExtension(".bashrc", ".md")         → ".bashrc"
EnsureExtension("/path/to/notes", ".md")  → "/path/to/notes.md"

func EnsureOutputDir

func EnsureOutputDir(dir string) error

EnsureOutputDir validates a directory path and creates it if it doesn't exist. Returns nil if the directory exists and is writable, or was successfully created. Returns an error describing the problem otherwise.

Note: Tilde expansion is performed via ExpandPath. If expansion fails (e.g., home directory cannot be determined), the path is used as-is, which will likely result in an error from os.Stat or os.MkdirAll.

func ExpandPath

func ExpandPath(path string) string

ExpandPath expands ~ or ~/path to the user's home directory. Returns the path unchanged if expansion fails or if it doesn't start with ~.

func Get

func Get(key string) (string, error)

Get reads a single value from the config file. Returns empty string if the key doesn't exist.

func List

func List() (map[string]string, error)

List returns all config values as a map.

func ResolveOutputPath

func ResolveOutputPath(output, outputDir, defaultName string) string

ResolveOutputPath resolves the final output path using the following precedence:

  1. If output is absolute, use it as-is
  2. If output is relative and outputDir is set, join them
  3. If output is empty, use defaultName in outputDir (or cwd if no outputDir)

outputDir can come from config or flag. All paths are cleaned using filepath.Clean to normalize separators and remove redundant elements.

func Save

func Save(key, value string) error

Save writes a single key=value to the config file. Creates the config directory and file if they don't exist. Preserves existing key=value pairs but discards comments. Returns ErrInvalidKey if the key contains = or newline characters.

WARNING: This function rewrites the entire config file. Any comments (lines starting with #) in the original file will be lost. This is a known limitation of the current implementation.

Types

type Config

type Config struct {
	OutputDir string
}

Config holds user configuration loaded from ~/.config/go-transcript/config.

func Load

func Load() (Config, error)

Load reads the configuration file and environment variables. Precedence: config file values, then environment variable fallbacks. Returns an empty Config if the file doesn't exist (not an error).

Jump to

Keyboard shortcuts

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