Files
actions-sync/src/sync.go

38 lines
740 B
Go
Raw Normal View History

2020-07-02 19:36:10 +01:00
package src
import (
"context"
"github.com/spf13/cobra"
)
type SyncFlags struct {
2020-09-18 16:50:26 -04:00
CommonFlags
PullOnlyFlags
PushOnlyFlags
2020-07-02 19:36:10 +01:00
}
func (f *SyncFlags) Init(cmd *cobra.Command) {
2020-09-18 16:50:26 -04:00
f.CommonFlags.Init(cmd)
f.PullOnlyFlags.Init(cmd)
f.PushOnlyFlags.Init(cmd)
2020-07-02 19:36:10 +01:00
}
func (f *SyncFlags) Validate() Validations {
2020-09-18 16:50:26 -04:00
return f.CommonFlags.Validate(true).Join(f.PullOnlyFlags.Validate().Join(f.PushOnlyFlags.Validate()))
2020-07-02 19:36:10 +01:00
}
2020-09-18 16:50:26 -04:00
func Sync(ctx context.Context, flags *SyncFlags) error {
pullFlags := &PullFlags{flags.CommonFlags, flags.PullOnlyFlags}
pushFlags := &PushFlags{flags.CommonFlags, flags.PushOnlyFlags}
if err := Pull(ctx, pullFlags); err != nil {
2020-07-02 19:36:10 +01:00
return err
}
2020-09-18 16:50:26 -04:00
if err := Push(ctx, pushFlags); err != nil {
2020-07-02 19:36:10 +01:00
return err
}
return nil
}