summaryrefslogtreecommitdiff
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
parent5b76547c3b3566ef878d0937b5cb1e91376d2206 (diff)
downloadaerc-c8017f67531c493451c6f25335990a74a1f81699.tar.gz
aerc-c8017f67531c493451c6f25335990a74a1f81699.zip
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>
-rw-r--r--config/accounts.go18
-rw-r--r--config/binds.go14
-rw-r--r--config/config.go23
-rw-r--r--doc/aerc-accounts.5.scd3
-rw-r--r--doc/aerc-binds.5.scd3
-rw-r--r--doc/aerc-config.5.scd3
-rw-r--r--doc/aerc.1.scd12
-rw-r--r--main.go18
8 files changed, 62 insertions, 32 deletions
diff --git a/config/accounts.go b/config/accounts.go
index dbc0cdb4..413b77b1 100644
--- a/config/accounts.go
+++ b/config/accounts.go
@@ -119,14 +119,16 @@ const (
var Accounts []*AccountConfig
-func parseAccounts(root string, accts []string) error {
- filename := path.Join(root, "accounts.conf")
- err := checkConfigPerms(filename)
- if errors.Is(err, os.ErrNotExist) {
- // No config triggers account configuration wizard
- return nil
- } else if err != nil {
- return err
+func parseAccounts(root string, accts []string, filename string) error {
+ if filename == "" {
+ filename = path.Join(root, "accounts.conf")
+ err := checkConfigPerms(filename)
+ if errors.Is(err, os.ErrNotExist) {
+ // No config triggers account configuration wizard
+ return nil
+ } else if err != nil {
+ return err
+ }
}
log.Debugf("Parsing accounts configuration from %s", filename)
diff --git a/config/binds.go b/config/binds.go
index 8eda890d..bedc6d9a 100644
--- a/config/binds.go
+++ b/config/binds.go
@@ -101,12 +101,14 @@ func defaultBindsConfig() *BindingConfig {
var Binds = defaultBindsConfig()
-func parseBinds(root string) error {
- filename := path.Join(root, "binds.conf")
- 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, "binds.conf"); err != nil {
- return err
+func parseBinds(root string, filename string) error {
+ if filename == "" {
+ filename = path.Join(root, "binds.conf")
+ 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, "binds.conf"); err != nil {
+ return err
+ }
}
}
log.Debugf("Parsing key bindings configuration from %s", filename)
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
}
diff --git a/doc/aerc-accounts.5.scd b/doc/aerc-accounts.5.scd
index 9d95af32..5f89033a 100644
--- a/doc/aerc-accounts.5.scd
+++ b/doc/aerc-accounts.5.scd
@@ -9,7 +9,8 @@ aerc-accounts - account configuration file format for *aerc*(1)
The _accounts.conf_ file is used for configuring each mail account used for
aerc. It is expected to be in your XDG config home plus _aerc_, which defaults
to _~/.config/aerc/accounts.conf_. This file must be kept secret, as it may
-include your account credentials.
+include your account credentials. An alternate file can be specified via the
+_--accounts-conf_ command line argument, see *aerc*(1).
If _accounts.conf_ does not exist, the *:new-account* configuration wizard will
be executed automatically on first startup.
diff --git a/doc/aerc-binds.5.scd b/doc/aerc-binds.5.scd
index f9cdd668..b00c12d8 100644
--- a/doc/aerc-binds.5.scd
+++ b/doc/aerc-binds.5.scd
@@ -9,7 +9,8 @@ aerc-binds - key bindings configuration file format for *aerc*(1)
The _binds.conf_ file is used for configuring keybindings used in the aerc
interactive client. It is expected to be in your XDG config home plus _aerc_,
which defaults to _~/.config/aerc/binds.conf_. If the file does not exist, the
-built-in default will be installed.
+built-in default will be installed. An alternate file can be specified via the
+_--binds-conf_ command line argument, see *aerc*(1).
This file is written in the ini format with key bindings defined as:
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 5acb9427..f3d45085 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -9,7 +9,8 @@ aerc-config - configuration file format for *aerc*(1)
There are three aerc config files: _aerc.conf_, _binds.conf_, and
_accounts.conf_. The last one must be kept secret, as it may include your
account credentials. We look for these files in your XDG config home plus
-_aerc_, which defaults to _~/.config/aerc_.
+_aerc_, which defaults to _~/.config/aerc_. Alternate files can be specified via
+command line arguments, see *aerc*(1).
Examples of these config files are typically included with your installation of
aerc and are usually installed in _/usr/share/aerc_.
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index ee5b27c5..5be01751 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -24,6 +24,18 @@ from your terminal.
can also be a comma separated list of names. This option may be
specified multiple times. The account order will be preserved.
+*--aerc-conf* _</path/to/aerc.conf>_
+ Instead of using _$XDG_CONFIG_HOME/aerc/aerc.conf_ use the file at the
+ specified path for configuring aerc.
+
+*--accounts-conf* _</path/to/accounts.conf>_
+ Instead of using _$XDG_CONFIG_HOME/aerc/accounts.conf_ use the file at the
+ specified path for configuring accounts.
+
+*--binds-conf* _</path/to/binds.conf>_
+ Instead of using _$XDG_CONFIG_HOME/aerc/binds.conf_ use the file at the
+ specified path for configuring binds.
+
*mailto:*_address[,address][?query[&query]]_
Open the composer with the address(es) in the To field. These
addresses must not be percent encoded.
diff --git a/main.go b/main.go
index ad926a63..06178d2d 100644
--- a/main.go
+++ b/main.go
@@ -119,10 +119,13 @@ func setWindowTitle() {
}
type Opts struct {
- Help bool `opt:"-h" action:"ShowHelp"`
- Version bool `opt:"-v" action:"ShowVersion"`
- Accounts []string `opt:"-a" action:"ParseAccounts" metavar:"<account>"`
- Command []string `opt:"..." required:"false" metavar:"mailto:<address> | mbox:<file> | :<command...>"`
+ Help bool `opt:"-h" action:"ShowHelp"`
+ Version bool `opt:"-v" action:"ShowVersion"`
+ Accounts []string `opt:"-a" action:"ParseAccounts" metavar:"<account>"`
+ ConfAerc string `opt:"--aerc-conf"`
+ ConfAccounts string `opt:"--accounts-conf"`
+ ConfBinds string `opt:"--binds-conf"`
+ Command []string `opt:"..." required:"false" metavar:"mailto:<address> | mbox:<file> | :<command...>"`
}
func (o *Opts) ShowHelp(arg string) error {
@@ -138,6 +141,9 @@ Options:
accounts. It can also be a comma separated list of names.
This option may be specified multiple times. The account
order will be preserved.
+ --aerc-conf Path to configuration file to be used instead of the default.
+ --accounts-conf Path to configuration file to be used instead of the default.
+ --binds-conf Path to configuration file to be used instead of the default.
mailto:<address> Open the composer with the address(es) in the To field.
If aerc is already running, the composer is started in
this instance, otherwise aerc will be started.
@@ -186,7 +192,9 @@ func main() {
retryExec = true
}
- err = config.LoadConfigFromFile(nil, opts.Accounts)
+ err = config.LoadConfigFromFile(
+ nil, opts.Accounts, opts.ConfAerc, opts.ConfBinds, opts.ConfAccounts,
+ )
if err != nil {
die("failed to load config: %s", err)
}