aboutsummaryrefslogtreecommitdiffstats
path: root/config/config.go
diff options
context:
space:
mode:
authorBence Ferdinandy <bence@ferdinandy.com>2024-01-20 21:29:23 +0100
committerRobin Jarry <robin@jarry.cc>2024-01-21 10:45:53 +0100
commitc8017f67531c493451c6f25335990a74a1f81699 (patch)
treeb8962baaae8caafcc2874f09a4bcb8bec2411e5d /config/config.go
parent5b76547c3b3566ef878d0937b5cb1e91376d2206 (diff)
downloadaerc-c8017f67531c493451c6f25335990a74a1f81699.tar.gz
main: add flags to override config files
Add --aerc-conf, --binds-conf and --accounts-conf CLI flags, which respectively override the default aerc.conf, binds.conf and accounts.conf configuration files. If the specified files do not exist or cannot be read, exit with an error. Implements: https://todo.sr.ht/~rjarry/aerc/209 Changelog-added: CLI flags to override paths to config files. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'config/config.go')
-rw-r--r--config/config.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/config/config.go b/config/config.go
index 092b73a6..1efbf896 100644
--- a/config/config.go
+++ b/config/config.go
@@ -77,18 +77,21 @@ func installTemplate(root, name string) error {
return nil
}
-func LoadConfigFromFile(root *string, accts []string) error {
+func LoadConfigFromFile(
+ root *string, accts []string, filename, bindPath, acctPath string,
+) error {
if root == nil {
_root := xdg.ConfigPath("aerc")
root = &_root
}
- filename := path.Join(*root, "aerc.conf")
-
- // if it doesn't exist copy over the template, then load
- if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
- fmt.Printf("%s not found, installing the system default\n", filename)
- if err := installTemplate(*root, "aerc.conf"); err != nil {
- return err
+ if filename == "" {
+ filename = path.Join(*root, "aerc.conf")
+ // if it doesn't exist copy over the template, then load
+ if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) {
+ fmt.Printf("%s not found, installing the system default\n", filename)
+ if err := installTemplate(*root, "aerc.conf"); err != nil {
+ return err
+ }
}
}
@@ -129,10 +132,10 @@ func LoadConfigFromFile(root *string, accts []string) error {
if err := parseTemplates(file); err != nil {
return err
}
- if err := parseAccounts(*root, accts); err != nil {
+ if err := parseAccounts(*root, accts, acctPath); err != nil {
return err
}
- if err := parseBinds(*root); err != nil {
+ if err := parseBinds(*root, bindPath); err != nil {
return err
}