// Config: parse config.yaml // SPDX-License-Identifier: GPL-3.0-or-later // Copyright (C) 2021-2024 Simon Ruderich package config import ( "fmt" "os" "gopkg.in/yaml.v2" "ruderich.org/simon/safcm" ) type Config struct { DryRun bool `yaml:"-"` // set via command line Quiet bool `yaml:"-"` // set via command line LogLevel safcm.LogLevel `yaml:"-"` // set via command line SshConfig string `yaml:"-"` // set via command line DetectGroups []string `yaml:"detect_groups"` GroupPriority []string `yaml:"group_priority"` SshUser string `yaml:"ssh_user"` } func LoadConfig() (*Config, error) { const path = "config.yaml" var cfg Config x, err := os.ReadFile(path) if err != nil { // This file is optional if os.IsNotExist(err) { return &cfg, nil } return nil, err } err = yaml.UnmarshalStrict(x, &cfg) if err != nil { return nil, fmt.Errorf("%s: failed to load: %v", path, err) } return &cfg, nil }