Files
yay/pkg/settings/lua/load.go
T
Jo 421b65bf43 feat: Add UpgradeSelect hook, logging and security example (#2855)
* add upgrade hook structure

* remove extra field

* feat: Add UpgradeSelect hook logging and security example

Add yay.log API to UpgradeSelect hooks for informational and warning messages.

- Add yay.log.info() and yay.log.warn() for hook logging
- Add doc/examples/recently_modified.lua: practical example to pre-exclude
  recently-modified AUR packages (supply chain attack mitigation)
- Update doc/init.lua with improved UpgradeSelect example
- Update doc/lua.md with logging API documentation
- Refactor autocmd and load modules for cleaner log integration
- Add comprehensive unit tests for logging functionality

* lint
2026-06-15 15:25:40 +02:00

57 lines
1.1 KiB
Go

package lua
import (
"fmt"
"github.com/Jguer/yay/v12/pkg/multierror"
"github.com/Jguer/yay/v12/pkg/text"
)
// Load loads path, applies its yay.opt values onto cfg, and returns the live engine.
func Load(logger *text.Logger, path string, cfg any) (*Engine, error) {
var luaLogger *text.Logger
if logger != nil {
luaLogger = logger.Child("lua")
}
engine := NewWithLogger(luaLogger)
if err := engine.L.DoFile(path); err != nil {
engine.Close()
return nil, err
}
unknown, errs := engine.Apply(cfg)
if len(unknown) == 0 && len(errs) == 0 {
return engine, nil
}
merr := &multierror.MultiError{}
for _, key := range unknown {
merr.Add(fmt.Errorf("init.lua: unknown yay.opt key: %s", key))
}
for _, err := range errs {
merr.Add(fmt.Errorf("init.lua: %w", err))
}
if err := merr.Return(); err != nil {
engine.Close()
return nil, err
}
return engine, nil
}
// LoadInto applies the yay.opt values from path onto cfg.
func LoadInto(logger *text.Logger, path string, cfg any) error {
engine, err := Load(logger, path, cfg)
if engine != nil {
defer engine.Close()
}
return err
}