Skip to content

Commit d02ca8c

Browse files
authored
Print help for 'databricks sync' without args (#2840)
## Changes Update argument checker to return an error that includes the help output. Fixes #1061. ## Why This is the current output: ``` $ databricks sync Error: flag: help requested ``` ## Tests New acceptance test.
1 parent 15c6f34 commit d02ca8c

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
>>> errcode [CLI] sync
3+
Error: accepts 2 arg(s), received 0
4+
5+
Usage:
6+
databricks sync [flags] SRC DST
7+
8+
Flags:
9+
--dry-run simulate sync execution without making actual changes
10+
--exclude strings patterns to exclude from sync (can be specified multiple times)
11+
--exclude-from string file containing patterns to exclude from sync (one pattern per line)
12+
--full perform full synchronization (default is incremental)
13+
-h, --help help for sync
14+
--include strings patterns to include in sync (can be specified multiple times)
15+
--include-from string file containing patterns to include to sync (one pattern per line)
16+
--interval duration file system polling interval (for --watch) (default 1s)
17+
--output type type of output format (default text)
18+
--watch watch local file system for changes
19+
20+
Global Flags:
21+
--debug enable debug logging
22+
-p, --profile string ~/.databrickscfg profile
23+
-t, --target string bundle target to use (if applicable)
24+
25+
26+
Exit code: 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
trace errcode $CLI sync

cmd/sync/sync.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"bytes"
66
"context"
77
"errors"
8-
"flag"
98
"fmt"
109
"io"
1110
"os"
@@ -94,8 +93,8 @@ func (f *syncFlags) syncOptionsFromBundle(cmd *cobra.Command, args []string, b *
9493
}
9594

9695
func (f *syncFlags) syncOptionsFromArgs(cmd *cobra.Command, args []string) (*sync.SyncOptions, error) {
97-
if len(args) != 2 {
98-
return nil, flag.ErrHelp
96+
if err := root.ExactArgs(2)(cmd, args); err != nil {
97+
return nil, err
9998
}
10099

101100
var outputFunc func(context.Context, <-chan sync.Event, io.Writer)

cmd/sync/sync_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package sync
22

33
import (
44
"context"
5-
"flag"
65
"os"
76
"path/filepath"
87
"strings"
@@ -47,11 +46,11 @@ func TestSyncOptionsFromArgsRequiredTwoArgs(t *testing.T) {
4746
var err error
4847
f := syncFlags{}
4948
_, err = f.syncOptionsFromArgs(New(), []string{})
50-
require.ErrorIs(t, err, flag.ErrHelp)
49+
require.ErrorContains(t, err, "accepts 2 arg(s), received 0")
5150
_, err = f.syncOptionsFromArgs(New(), []string{"foo"})
52-
require.ErrorIs(t, err, flag.ErrHelp)
51+
require.ErrorContains(t, err, "accepts 2 arg(s), received 1")
5352
_, err = f.syncOptionsFromArgs(New(), []string{"foo", "bar", "qux"})
54-
require.ErrorIs(t, err, flag.ErrHelp)
53+
require.ErrorContains(t, err, "accepts 2 arg(s), received 3")
5554
}
5655

5756
func TestSyncOptionsFromArgs(t *testing.T) {

0 commit comments

Comments
 (0)