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