~rjarry/aerc-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
7 4

[PATCH aerc] feat: add cli flag to load specified account

Details
Message ID
<20220810020745.52194-1-tim@timculverhouse.com>
DKIM signature
missing
Download raw message
Patch: +16 -7
Make it possible to specify a single account to load, even when multiple
accounts are configured in accounts.conf.

	aerc -a <account-name>

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
---
 aerc.go          | 10 +++++++---
 config/config.go |  9 ++++++---
 doc/aerc.1.scd   |  4 +++-
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/aerc.go b/aerc.go
index 6e6c1d140db7..4d350339c073 100644
--- a/aerc.go
+++ b/aerc.go
@@ -92,7 +92,7 @@ var Version string

func usage(msg string) {
	fmt.Fprintln(os.Stderr, msg)
	fmt.Fprintln(os.Stderr, "usage: aerc [-v] [mailto:...]")
	fmt.Fprintln(os.Stderr, "usage: aerc [-v] [mailto:...] [-a <account-name>]")
	os.Exit(1)
}

@@ -119,16 +119,20 @@ func setWindowTitle() {

func main() {
	defer logging.PanicHandler()
	opts, optind, err := getopt.Getopts(os.Args, "v")
	opts, optind, err := getopt.Getopts(os.Args, "va:")
	if err != nil {
		usage("error: " + err.Error())
		return
	}
	var soleAcct string
	for _, opt := range opts {
		if opt.Option == 'v' {
			fmt.Println("aerc " + Version)
			return
		}
		if opt.Option == 'a' {
			soleAcct = opt.Value
		}
	}
	retryExec := false
	args := os.Args[optind:]
@@ -151,7 +155,7 @@ func main() {
	}
	logging.Infof("Starting up")

	conf, err := config.LoadConfigFromFile(nil)
	conf, err := config.LoadConfigFromFile(nil, soleAcct)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to load config: %v\n", err)
		os.Exit(1) //nolint:gocritic // PanicHandler does not need to run as it's not a panic
diff --git a/config/config.go b/config/config.go
index 66c6dd19c912..ecfdea22a45a 100644
--- a/config/config.go
+++ b/config/config.go
@@ -266,7 +266,7 @@ func mapName(raw string) string {
	return string(newstr)
}

func loadAccountConfig(path string) ([]AccountConfig, error) {
func loadAccountConfig(path string, soleAcct string) ([]AccountConfig, error) {
	file, err := ini.Load(path)
	if err != nil {
		// No config triggers account configuration wizard
@@ -279,6 +279,9 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
		if _sec == "DEFAULT" {
			continue
		}
		if soleAcct != "" && _sec != soleAcct {
			continue
		}
		sec := file.Section(_sec)
		sourceRemoteConfig := RemoteConfig{}
		account := AccountConfig{
@@ -663,7 +666,7 @@ func validatePgpProvider(section *ini.Section) error {
	return nil
}

func LoadConfigFromFile(root *string) (*AercConfig, error) {
func LoadConfigFromFile(root *string, soleAcct string) (*AercConfig, error) {
	if root == nil {
		_root := path.Join(xdg.ConfigHome(), "aerc")
		root = &_root
@@ -823,7 +826,7 @@ func LoadConfigFromFile(root *string) (*AercConfig, error) {

	accountsPath := path.Join(*root, "accounts.conf")
	logging.Infof("Parsing accounts configuration from %s", accountsPath)
	if accounts, err := loadAccountConfig(accountsPath); err != nil {
	if accounts, err := loadAccountConfig(accountsPath, soleAcct); err != nil {
		return nil, err
	} else {
		config.Accounts = accounts
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 17e25c2ac480..9cda61bfcce8 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -6,7 +6,7 @@ aerc - the world's best email client

# SYNOPSIS

_aerc_ [-v] [mailto:...]
_aerc_ [-v] [mailto:...] [-a <account-name>]

For a guided tutorial, use *:help tutorial* from aerc, or *man aerc-tutorial*
from your terminal.
@@ -40,6 +40,8 @@ from your terminal.

	Note that reserved characters in the queries must be percent encoded.

*-a <account-name>* 
	Load only the named account, as opposed to all configured accounts.

# RUNTIME COMMANDS

-- 
2.37.1

[aerc/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CM1ZGAS47YW4.2TT2XONKALFC1@cirno2>
In-Reply-To
<20220810020745.52194-1-tim@timculverhouse.com> (view parent)
DKIM signature
missing
Download raw message
aerc/patches: SUCCESS in 3m53s

[feat: add cli flag to load specified account][0] from [Tim Culverhouse][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/34575
[1]: tim@timculverhouse.com

✓ #820025 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/820025
✓ #820024 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/820024
Details
Message ID
<CM20BY6191O4.222BJG3D0W9QF@nano>
In-Reply-To
<20220810020745.52194-1-tim@timculverhouse.com> (view parent)
DKIM signature
missing
Download raw message
On Tue Aug 9, 2022 at 7:07 PM PDT, Tim Culverhouse wrote:
> Make it possible to specify a single account to load, even when multiple
> accounts are configured in accounts.conf.
>
> 	aerc -a <account-name>

i like the idea.  tried it out, and it seems to work.  in fact, this is
how i invoked aerc to compose this message :)

Tested-by: akspecs <akspecs@gmail.com>
>
> Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
> ---
>  aerc.go          | 10 +++++++---
>  config/config.go |  9 ++++++---
>  doc/aerc.1.scd   |  4 +++-
>  3 files changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/aerc.go b/aerc.go
> index 6e6c1d140db7..4d350339c073 100644
> --- a/aerc.go
> +++ b/aerc.go
> @@ -92,7 +92,7 @@ var Version string
>  
>  func usage(msg string) {
>  	fmt.Fprintln(os.Stderr, msg)
> -	fmt.Fprintln(os.Stderr, "usage: aerc [-v] [mailto:...]")
> +	fmt.Fprintln(os.Stderr, "usage: aerc [-v] [mailto:...] [-a <account-name>]")
>  	os.Exit(1)
>  }
>  
> @@ -119,16 +119,20 @@ func setWindowTitle() {
>  
>  func main() {
>  	defer logging.PanicHandler()
> -	opts, optind, err := getopt.Getopts(os.Args, "v")
> +	opts, optind, err := getopt.Getopts(os.Args, "va:")
>  	if err != nil {
>  		usage("error: " + err.Error())
>  		return
>  	}
> +	var soleAcct string
>  	for _, opt := range opts {
>  		if opt.Option == 'v' {
>  			fmt.Println("aerc " + Version)
>  			return
>  		}
> +		if opt.Option == 'a' {
> +			soleAcct = opt.Value
> +		}
>  	}
>  	retryExec := false
>  	args := os.Args[optind:]
> @@ -151,7 +155,7 @@ func main() {
>  	}
>  	logging.Infof("Starting up")
>  
> -	conf, err := config.LoadConfigFromFile(nil)
> +	conf, err := config.LoadConfigFromFile(nil, soleAcct)
>  	if err != nil {
>  		fmt.Fprintf(os.Stderr, "Failed to load config: %v\n", err)
>  		os.Exit(1) //nolint:gocritic // PanicHandler does not need to run as it's not a panic
> diff --git a/config/config.go b/config/config.go
> index 66c6dd19c912..ecfdea22a45a 100644
> --- a/config/config.go
> +++ b/config/config.go
> @@ -266,7 +266,7 @@ func mapName(raw string) string {
>  	return string(newstr)
>  }
>  
> -func loadAccountConfig(path string) ([]AccountConfig, error) {
> +func loadAccountConfig(path string, soleAcct string) ([]AccountConfig, error) {
>  	file, err := ini.Load(path)
>  	if err != nil {
>  		// No config triggers account configuration wizard
> @@ -279,6 +279,9 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
>  		if _sec == "DEFAULT" {
>  			continue
>  		}
> +		if soleAcct != "" && _sec != soleAcct {
> +			continue
> +		}
>  		sec := file.Section(_sec)
>  		sourceRemoteConfig := RemoteConfig{}
>  		account := AccountConfig{
> @@ -663,7 +666,7 @@ func validatePgpProvider(section *ini.Section) error {
>  	return nil
>  }
>  
> -func LoadConfigFromFile(root *string) (*AercConfig, error) {
> +func LoadConfigFromFile(root *string, soleAcct string) (*AercConfig, error) {
>  	if root == nil {
>  		_root := path.Join(xdg.ConfigHome(), "aerc")
>  		root = &_root
> @@ -823,7 +826,7 @@ func LoadConfigFromFile(root *string) (*AercConfig, error) {
>  
>  	accountsPath := path.Join(*root, "accounts.conf")
>  	logging.Infof("Parsing accounts configuration from %s", accountsPath)
> -	if accounts, err := loadAccountConfig(accountsPath); err != nil {
> +	if accounts, err := loadAccountConfig(accountsPath, soleAcct); err != nil {
>  		return nil, err
>  	} else {
>  		config.Accounts = accounts
> diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
> index 17e25c2ac480..9cda61bfcce8 100644
> --- a/doc/aerc.1.scd
> +++ b/doc/aerc.1.scd
> @@ -6,7 +6,7 @@ aerc - the world's best email client
>  
>  # SYNOPSIS
>  
> -_aerc_ [-v] [mailto:...]
> +_aerc_ [-v] [mailto:...] [-a <account-name>]
>  
>  For a guided tutorial, use *:help tutorial* from aerc, or *man aerc-tutorial*
>  from your terminal.
> @@ -40,6 +40,8 @@ from your terminal.
>  
>  	Note that reserved characters in the queries must be percent encoded.
>  
> +*-a <account-name>* 

nit picking here: git complained about applying a patch with trailing
whitespace.  i believe this is it, though another look at some of aerc's
scd doc files will show that there's a number of instances with trailing
whitespace.  or are those intentional?

> +	Load only the named account, as opposed to all configured accounts.
>  
>  # RUNTIME COMMANDS
>  
> -- 
> 2.37.1
Details
Message ID
<CM2J9M2XOTCZ.2KGBQ4W5P7DIE@marty>
In-Reply-To
<20220810020745.52194-1-tim@timculverhouse.com> (view parent)
DKIM signature
missing
Download raw message
Tim Culverhouse, Aug 10, 2022 at 04:07:
> Make it possible to specify a single account to load, even when multiple
> accounts are configured in accounts.conf.
>
> 	aerc -a <account-name>
>
> Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>

Hmm, I'm not sure I see the use case for such a feature. Maybe a way to
start with a default selected account would make more sense.

What do you think?
Details
Message ID
<CM2JDPOUS9A0.3K8RIAOSW58K3@TimBook-Arch>
In-Reply-To
<CM2J9M2XOTCZ.2KGBQ4W5P7DIE@marty> (view parent)
DKIM signature
missing
Download raw message
On Wed Aug 10, 2022 at 12:43 PM CDT, Robin Jarry wrote:
> Hmm, I'm not sure I see the use case for such a feature. Maybe a way to
> start with a default selected account would make more sense.
>
> What do you think?

Here's a few use cases for this specifically:

1. Development: I have imap, maildir, mbox, notmuch, and gmail accounts.
I only *actually* want to use imap, but for development I have each set
up. It's annoying to go into my acct config and comment out the ones I
don't want at certain times.

2. "Focus": If I *could* have my work email in aerc, I might want to be
able to have EITHER my personal OR my work email open, but not both at
the same time. I considered a "close account tab" feature to do this,
but it seemed cleaner to just not load the account in the first place.

3. Similar to 2, I could have multiple aerc instances with different
accounts open in each one - so that there is a nice separation if you
get confused easily :)

Tim
Details
Message ID
<CM2K6S00AELI.11KOH9Z4SZ7K6@nano>
In-Reply-To
<CM2JDPOUS9A0.3K8RIAOSW58K3@TimBook-Arch> (view parent)
DKIM signature
missing
Download raw message
On Wed Aug 10, 2022 at 10:48 AM PDT, Tim Culverhouse wrote:
> On Wed Aug 10, 2022 at 12:43 PM CDT, Robin Jarry wrote:
> > Hmm, I'm not sure I see the use case for such a feature. Maybe a way to
> > start with a default selected account would make more sense.
> >
> > What do you think?

i do believe there can be room for both the behaviour you describe, as
well as there being merit to Tim's described use case.

if possible, i'd consider adding the ability to specify more than one
account that you may want appearing in that particular invocation of
aerc  -- as well as which one to have selected by default.  however, it
does seem that this patch is useful as is.
>
> Here's a few use cases for this specifically:
>
> 1. Development: I have imap, maildir, mbox, notmuch, and gmail accounts.
> I only *actually* want to use imap, but for development I have each set
> up. It's annoying to go into my acct config and comment out the ones I
> don't want at certain times.
>
> 2. "Focus": If I *could* have my work email in aerc, I might want to be
> able to have EITHER my personal OR my work email open, but not both at
> the same time. I considered a "close account tab" feature to do this,
> but it seemed cleaner to just not load the account in the first place.
>
> 3. Similar to 2, I could have multiple aerc instances with different
> accounts open in each one - so that there is a nice separation if you
> get confused easily :)

admittedly, the ugly way i've accomplished this by having a copy of each
accounts.conf.account-name or combination of accounts set up in advance,
and then having a shell alias / function that would copy or link into
place the preferred config i'd like to use for that invocation of aerc.

i much prefer the approach with this patch, as it's a good start for
these issues described.
Details
Message ID
<CM2LRJ38O41C.324XWR127K5YU@marty>
In-Reply-To
<20220810020745.52194-1-tim@timculverhouse.com> (view parent)
DKIM signature
missing
Download raw message
Tim Culverhouse, Aug 10, 2022 at 04:07:
> Make it possible to specify a single account to load, even when multiple
> accounts are configured in accounts.conf.
>
> 	aerc -a <account-name>

I think it would not be complex to allow a coma-separated list of
account names. This could also allow forcing the account order. Do you
think you could change this?

> diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
> index 17e25c2ac480..9cda61bfcce8 100644
> --- a/doc/aerc.1.scd
> +++ b/doc/aerc.1.scd
> @@ -6,7 +6,7 @@ aerc - the world's best email client
>  
>  # SYNOPSIS
>  
> -_aerc_ [-v] [mailto:...]
> +_aerc_ [-v] [mailto:...] [-a <account-name>]
>  
>  For a guided tutorial, use *:help tutorial* from aerc, or *man aerc-tutorial*
>  from your terminal.
> @@ -40,6 +40,8 @@ from your terminal.
>  
>  	Note that reserved characters in the queries must be percent encoded.
>  
> +*-a <account-name>* 

Please remove trailing white space.
Details
Message ID
<CM2M95XNYU1A.2GELRXAGOBE3A@TimBook-Arch>
In-Reply-To
<CM2LRJ38O41C.324XWR127K5YU@marty> (view parent)
DKIM signature
missing
Download raw message
On Wed Aug 10, 2022 at 2:40 PM CDT, Robin Jarry wrote:
> I think it would not be complex to allow a coma-separated list of
> account names. This could also allow forcing the account order. Do you
> think you could change this?

Can do!

> Please remove trailing white space.

Ack.

Tim
Reply to thread Export thread (mbox)