Skip to content

Commit 3b7c320

Browse files
committed
fix arg validation order
1 parent fbe56f4 commit 3b7c320

2 files changed

Lines changed: 6 additions & 23 deletions

File tree

cmd/sync/sync.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@ type syncFlags struct {
4040
concurrency int
4141
}
4242

43-
func (f *syncFlags) validate() error {
44-
if f.concurrency < 1 {
45-
return errInvalidConcurrency
46-
}
47-
return nil
48-
}
49-
5043
func readPatternsFile(filePath string) ([]string, error) {
5144
if filePath == "" {
5245
return nil, nil
@@ -207,12 +200,13 @@ func New() *cobra.Command {
207200
return root.MustWorkspaceClient(cmd, args)
208201
}
209202

210-
cmd.PreRunE = mustWorkspaceClient
211-
cmd.RunE = func(cmd *cobra.Command, args []string) error {
212-
if err := f.validate(); err != nil {
213-
return err
203+
cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
204+
if f.concurrency < 1 {
205+
return errInvalidConcurrency
214206
}
215-
207+
return mustWorkspaceClient(cmd, args)
208+
}
209+
cmd.RunE = func(cmd *cobra.Command, args []string) error {
216210
var opts *sync.SyncOptions
217211
var err error
218212

cmd/sync/sync_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,6 @@ func TestSyncOptionsFromArgs(t *testing.T) {
6767
assert.Equal(t, 7, opts.Concurrency)
6868
}
6969

70-
func TestSyncFlagsValidate(t *testing.T) {
71-
f := syncFlags{concurrency: 1}
72-
require.NoError(t, f.validate())
73-
74-
f.concurrency = 0
75-
require.ErrorIs(t, f.validate(), errInvalidConcurrency)
76-
77-
f.concurrency = -3
78-
require.ErrorIs(t, f.validate(), errInvalidConcurrency)
79-
}
80-
8170
func TestExcludeFromFlag(t *testing.T) {
8271
// Create a temporary directory
8372
tempDir := t.TempDir()

0 commit comments

Comments
 (0)