Honor repo flags on sync and push

This commit is contained in:
Chris Sidi
2020-09-18 16:50:26 -04:00
parent bc20d5071b
commit 8862a56600
7 changed files with 269 additions and 133 deletions
+14 -8
View File
@@ -7,24 +7,30 @@ import (
)
type SyncFlags struct {
PullFlags
PushFlags
CommonFlags
PullOnlyFlags
PushOnlyFlags
}
func (f *SyncFlags) Init(cmd *cobra.Command) {
f.PullFlags.Init(cmd)
f.PushFlags.Init(cmd)
f.CommonFlags.Init(cmd)
f.PullOnlyFlags.Init(cmd)
f.PushOnlyFlags.Init(cmd)
}
func (f *SyncFlags) Validate() Validations {
return f.PullFlags.Validate().Join(f.PushFlags.Validate())
return f.CommonFlags.Validate(true).Join(f.PullOnlyFlags.Validate().Join(f.PushOnlyFlags.Validate()))
}
func Sync(ctx context.Context, cacheDir string, flags *SyncFlags) error {
if err := Pull(ctx, cacheDir, &flags.PullFlags); err != nil {
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 {
return err
}
if err := Push(ctx, cacheDir, &flags.PushFlags); err != nil {
if err := Push(ctx, pushFlags); err != nil {
return err
}
return nil