~rockorager/offmap

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

[PATCH offmap v3] offmap: add -a, --account flag

Details
Message ID
<20221207140313.164704-1-tim@timculverhouse.com>
DKIM signature
missing
Download raw message
Patch: +38 -3
Add a flag to sync the specified account

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
---
v3: moved logic into config loading

 cmd/diff.go      |  8 +++++++-
 cmd/sync.go      |  8 +++++++-
 config.go        | 15 ++++++++++++++-
 doc/offmap.1.scd | 10 ++++++++++
 4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/cmd/diff.go b/cmd/diff.go
index 6855bf40083a..71a7d06e310e 100644
--- a/cmd/diff.go
+++ b/cmd/diff.go
@@ -16,13 +16,19 @@ func newDiffCommand() *cobra.Command {
		Short: "diff enumerates changes from last sync for a mailstore",
		Run:   diff,
	}
	cmd.Flags().StringSliceP("account", "a", nil, "only sync the specified account(s)")
	return cmd
}

func diff(cmd *cobra.Command, args []string) {
	verbosity, _ := cmd.Flags().GetCount("verbose")
	log.SetLevel(verbosity)
	cfgs, err := offmap.LoadConfig()
	accts, err := cmd.Flags().GetStringSlice("account")
	if err != nil {
		log.Errorf("offmap: could not parse account: %v", err)
		return
	}
	cfgs, err := offmap.LoadConfig(accts)
	if err != nil {
		log.Fatalf("could not read config: %v", err)
	}
diff --git a/cmd/sync.go b/cmd/sync.go
index de6782dcc285..ddd444486001 100644
--- a/cmd/sync.go
+++ b/cmd/sync.go
@@ -16,13 +16,19 @@ func newSyncCommand() *cobra.Command {
		Short: "sync synchronizes mail stores",
		Run:   sync,
	}
	cmd.Flags().StringSliceP("account", "a", nil, "only sync the specified account(s)")
	return cmd
}

func sync(cmd *cobra.Command, args []string) {
	verbosity, _ := cmd.Flags().GetCount("verbose")
	log.SetLevel(verbosity)
	cfgs, err := offmap.LoadConfig()
	accts, err := cmd.Flags().GetStringSlice("account")
	if err != nil {
		log.Errorf("offmap: could not parse account: %v", err)
		return
	}
	cfgs, err := offmap.LoadConfig(accts)
	if err != nil {
		log.Debugf("%v", err)
	}
diff --git a/config.go b/config.go
index cf7fedcd6d2f..e6fc2016d5d0 100644
--- a/config.go
+++ b/config.go
@@ -20,7 +20,7 @@ type Config struct {
	MaxConnections int    `toml:"max-connections"`
}

func LoadConfig() ([]*Config, error) {
func LoadConfig(accts []string) ([]*Config, error) {
	xdg, err := os.UserConfigDir()
	if err != nil {
		return nil, fmt.Errorf("config: %w", err)
@@ -49,6 +49,9 @@ func LoadConfig() ([]*Config, error) {

	cfgs := []*Config{}
	for k, cfg := range cfgMap {
		if len(accts) > 0 && notContains(k, accts) {
			continue
		}
		cfg.Name = k
		err := validate(cfg)
		if err != nil {
@@ -79,3 +82,13 @@ func validate(cfg *Config) error {
	}
	return nil
}

// returns true if the target is not contained in the slice
func notContains(target string, items []string) bool {
	for _, item := range items {
		if item == target {
			return false
		}
	}
	return true
}
diff --git a/doc/offmap.1.scd b/doc/offmap.1.scd
index a35462753d66..bdfcee241a23 100644
--- a/doc/offmap.1.scd
+++ b/doc/offmap.1.scd
@@ -17,6 +17,16 @@ offmap - an email synchronizer

# OPTIONS

*-a, --account* <name[,name]>
	Only sync the specified account(s). Can be passed more than one time to
	specify multiple accounts, or a comma separated list can be used:

	Example:
	```
	offmap sync -a personal,work
	offmap sync -a personal -a work
	```

*-v, --verbose*
	Increase verbosity level. Can be used multiple times

-- 
2.38.1

[offmap/patches/.build.yml] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<COVN5HS235WF.3SH3WCN12D95A@cirno2>
In-Reply-To
<20221207140313.164704-1-tim@timculverhouse.com> (view parent)
DKIM signature
missing
Download raw message
offmap/patches/.build.yml: SUCCESS in 2m2s

[offmap: add -a, --account flag][0] v3 from [Tim Culverhouse][1]

[0]: https://lists.sr.ht/~rockorager/offmap/patches/37388
[1]: tim@timculverhouse.com

✓ #900086 SUCCESS offmap/patches/.build.yml https://builds.sr.ht/~rockorager/job/900086
Details
Message ID
<COVN8N28YPWG.2P1OAEC16ZPW3@spunky>
In-Reply-To
<20221207140313.164704-1-tim@timculverhouse.com> (view parent)
DKIM signature
missing
Download raw message
On Wed Dec 7, 2022 at 8:03 AM CST, Tim Culverhouse wrote:
> Add a flag to sync the specified account
>
> Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
> ---
> v3: moved logic into config loading

I guess this is actually v4
Details
Message ID
<COX3A44QG8VC.2PEFF1NEL19YF@hera>
In-Reply-To
<20221207140313.164704-1-tim@timculverhouse.com> (view parent)
DKIM signature
missing
Download raw message
On Wed Dec 7, 2022 at 3:03 PM CET, Tim Culverhouse wrote:
> diff --git a/config.go b/config.go
> index cf7fedcd6d2f..e6fc2016d5d0 100644
> --- a/config.go
> +++ b/config.go
> @@ -79,3 +82,13 @@ func validate(cfg *Config) error {
>  	}
>  	return nil
>  }
> +
> +// returns true if the target is not contained in the slice
> +func notContains(target string, items []string) bool {
Still think a map would be better, but this works as well :)

> +	for _, item := range items {
> +		if item == target {
> +			return false
> +		}
> +	}
> +	return true
> +}

Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
-- 
Moritz Poldrack
https://moritz.sh
Details
Message ID
<COXBNQ8X6ZUC.2AY72J81FT49N@spunky>
In-Reply-To
<COX3A44QG8VC.2PEFF1NEL19YF@hera> (view parent)
DKIM signature
missing
Download raw message
On Fri Dec 9, 2022 at 12:57 AM CST, Moritz Poldrack wrote:
> Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>

Thanks! Applied.
Reply to thread Export thread (mbox)