// Package uoscconf parses, edits, and writes uOSC's uosc.conf // (mpv script-opts) while preserving comments and untouched lines. The // parse/edit/atomic-write machinery is shared with other script-opts confs // in internal/scriptopts; this package holds the uOSC option catalog and // file naming. package uoscconf import ( "gitgud.io/mike/mpv-manager/internal/scriptopts" ) // confFileName is the uOSC script-opts file name. const confFileName = "uosc.conf" // UOSCConf holds the parsed representation of a uosc.conf file. type UOSCConf struct { file *scriptopts.File } // GetUOSCConfPath returns the platform-aware path to the user's // uosc.conf, in the script-opts directory next to mpv.conf. func GetUOSCConfPath() (string, error) { return scriptopts.ConfPath(confFileName) } // ParseUOSCConf reads and parses the uosc.conf at path. // A missing file is not an error: the returned conf has no explicit entries // and GetValue falls back to the KnownOptions defaults. func ParseUOSCConf(path string) (*UOSCConf, error) { file, err := scriptopts.Parse(spec, path) if err != nil { return nil, err } return &UOSCConf{file: file}, nil } // GetValue returns the explicitly set value for key, or the KnownOptions // default when the user has no explicit line. Unknown keys return "". func (c *UOSCConf) GetValue(key string) string { return c.file.GetValue(key) } // IsSet reports whether the user has an explicit line for key. func (c *UOSCConf) IsSet(key string) bool { return c.file.IsSet(key) } // SetValue sets key to value after validating it against KnownOptions. // An existing line is updated in place (preserving position and inline // comment); a new key is appended at the end of the file. func (c *UOSCConf) SetValue(key, value string) error { return c.file.SetValue(key, value) } // ResetValue removes the explicit line(s) for key, reverting it to the // KnownOptions default. Unknown keys are rejected. func (c *UOSCConf) ResetValue(key string) error { return c.file.ResetValue(key) } // Write writes the conf back to disk using an atomic write pattern. // A timestamped backup of any existing file is created before overwriting. func (c *UOSCConf) Write() error { return c.file.Write() } // SetValueFile applies one option to a fresh file snapshot while holding the // path lock through backup and atomic replacement. func SetValueFile(path, key, value string) error { return scriptopts.SetValueFile(spec, path, key, value) } // ResetValueFile removes one explicit option from a fresh file snapshot while // holding the path lock through backup and atomic replacement. func ResetValueFile(path, key string) error { return scriptopts.ResetValueFile(spec, path, key) }