~rockorager/offmap

offmap: offmap: add -a, --account flag v3 APPLIED

Tim Culverhouse: 1
 offmap: add -a, --account flag

 4 files changed, 38 insertions(+), 3 deletions(-)
#900086 .build.yml success
Thanks! Applied.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rockorager/offmap/patches/37388/mbox | git am -3
Learn more about email & git

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

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: SUCCESS in 2m2s

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

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

✓ #900086 SUCCESS offmap/patches/.build.yml https://builds.sr.ht/~rockorager/job/900086
Still think a map would be better, but this works as well :)