~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
3 3

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

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

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
---
 cmd/diff.go | 9 +++++++++
 cmd/sync.go | 9 +++++++++
 2 files changed, 18 insertions(+)

diff --git a/cmd/diff.go b/cmd/diff.go
index 6855bf4..d0844f6 100644
--- a/cmd/diff.go
+++ b/cmd/diff.go
@@ -16,6 +16,7 @@ func newDiffCommand() *cobra.Command {
		Short: "diff enumerates changes from last sync for a mailstore",
		Run:   diff,
	}
	cmd.Flags().StringP("account", "a", "", "only diff the specified account")
	return cmd
}

@@ -26,7 +27,15 @@ func diff(cmd *cobra.Command, args []string) {
	if err != nil {
		log.Fatalf("could not read config: %v", err)
	}
	acct, err := cmd.Flags().GetString("account")
	if err != nil {
		log.Errorf("offmap: could not parse account: %v", err)
		return
	}
	for _, cfg := range cfgs {
		if acct != "" && acct != cfg.Name {
			continue
		}
		start := time.Now()

		// Bootstrap the app
diff --git a/cmd/sync.go b/cmd/sync.go
index de6782d..4dcd6a2 100644
--- a/cmd/sync.go
+++ b/cmd/sync.go
@@ -16,6 +16,7 @@ func newSyncCommand() *cobra.Command {
		Short: "sync synchronizes mail stores",
		Run:   sync,
	}
	cmd.Flags().StringP("account", "a", "", "only sync the specified account")
	return cmd
}

@@ -26,7 +27,15 @@ func sync(cmd *cobra.Command, args []string) {
	if err != nil {
		log.Debugf("%v", err)
	}
	acct, err := cmd.Flags().GetString("account")
	if err != nil {
		log.Errorf("offmap: could not parse account: %v", err)
		return
	}
	for _, cfg := range cfgs {
		if acct != "" && acct != cfg.Name {
			continue
		}
		log.Infof("offmap: syncing account %s", cfg.Name)
		start := time.Now()

-- 
2.38.1

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

builds.sr.ht <builds@sr.ht>
Details
Message ID
<COUETBRAT59X.23VMHR6L78KWU@cirno>
In-Reply-To
<20221206031838.41934-1-tim@timculverhouse.com> (view parent)
DKIM signature
missing
Download raw message
offmap/patches/.build.yml: SUCCESS in 1m54s

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

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

✓ #899031 SUCCESS offmap/patches/.build.yml https://builds.sr.ht/~rockorager/job/899031
Details
Message ID
<COUKGS0J0S8R.2TZNH1ZSM86KK@hera>
In-Reply-To
<20221206031838.41934-1-tim@timculverhouse.com> (view parent)
DKIM signature
missing
Download raw message
On Tue Dec 6, 2022 at 4:18 AM CET, Tim Culverhouse wrote:
> Add a flag to sync the specified account
>
> Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
> ---
>  cmd/diff.go | 9 +++++++++
>  cmd/sync.go | 9 +++++++++
>  2 files changed, 18 insertions(+)
>
> diff --git a/cmd/diff.go b/cmd/diff.go
> index 6855bf4..d0844f6 100644
> --- a/cmd/diff.go
> +++ b/cmd/diff.go
> @@ -16,6 +16,7 @@ func newDiffCommand() *cobra.Command {
>  		Short: "diff enumerates changes from last sync for a mailstore",
>  		Run:   diff,
>  	}
> +	cmd.Flags().StringP("account", "a", "", "only diff the specified account")
>  	return cmd
>  }
>  
> @@ -26,7 +27,15 @@ func diff(cmd *cobra.Command, args []string) {
>  	if err != nil {
>  		log.Fatalf("could not read config: %v", err)
>  	}
> +	acct, err := cmd.Flags().GetString("account")
> +	if err != nil {
> +		log.Errorf("offmap: could not parse account: %v", err)
> +		return
> +	}
>  	for _, cfg := range cfgs {
I think it would be easy to just right away implement support for
multiple accounts by either specifying -a multiple times, or splitting
by `,`. What do you think?

so: -a Personal,Work
is converted to map[string]bool{"Personal":true,"Work": true}

> +		if acct != "" && acct != cfg.Name {
> +			continue
> +		}
>  		start := time.Now()
>  
>  		// Bootstrap the app
> diff --git a/cmd/sync.go b/cmd/sync.go
> index de6782d..4dcd6a2 100644
> --- a/cmd/sync.go
> +++ b/cmd/sync.go
> @@ -16,6 +16,7 @@ func newSyncCommand() *cobra.Command {
>  		Short: "sync synchronizes mail stores",
>  		Run:   sync,
>  	}
> +	cmd.Flags().StringP("account", "a", "", "only sync the specified account")
>  	return cmd
>  }
>  
> @@ -26,7 +27,15 @@ func sync(cmd *cobra.Command, args []string) {
>  	if err != nil {
>  		log.Debugf("%v", err)
>  	}
> +	acct, err := cmd.Flags().GetString("account")
> +	if err != nil {
> +		log.Errorf("offmap: could not parse account: %v", err)
> +		return
> +	}
>  	for _, cfg := range cfgs {
> +		if acct != "" && acct != cfg.Name {
> +			continue
> +		}
Same as above. :)

>  		log.Infof("offmap: syncing account %s", cfg.Name)
>  		start := time.Now()
>  
> -- 
> 2.38.1

-- 
Moritz Poldrack
https://moritz.sh
Details
Message ID
<COUSSD42GNIJ.1UFO0GBAN2R6L@spunky>
In-Reply-To
<COUKGS0J0S8R.2TZNH1ZSM86KK@hera> (view parent)
DKIM signature
missing
Download raw message
On Tue Dec 6, 2022 at 1:49 AM CST, Moritz Poldrack wrote:
> I think it would be easy to just right away implement support for
> multiple accounts by either specifying -a multiple times, or splitting
> by `,`. What do you think?
>
> so: -a Personal,Work
> is converted to map[string]bool{"Personal":true,"Work": true}

Good idea!

cobra supports two of these out of the box, i think StringSlice is what we want:

It can support both of these:

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

I'll send a v2

--
Tim
Reply to thread Export thread (mbox)