Skip to content

Commit

Permalink
Remove variadic args for Common and Cache flags
Browse files Browse the repository at this point in the history
Signed-off-by: pavel.larkin <[email protected]>
  • Loading branch information
plar committed Feb 12, 2024
1 parent d0a6dd1 commit 246e1c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
28 changes: 4 additions & 24 deletions pkg/kopia/cli/internal/flag/common/common_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,8 @@ func (f common) Apply(cmd safecli.CommandAppender) error {
}

// Common creates a new common flag.
// If no arguments are provided, the default common flags are used.
// If one argument is provided, the common flags are used.
// If more than one argument is provided, ErrInvalidCommonArgs is returned.
func Common(args ...cli.CommonArgs) flag.Applier {
switch len(args) {
case 0:
return common{cli.CommonArgs{}}
case 1:
return common{args[0]}
default:
return flag.ErrorFlag(cli.ErrInvalidCommonArgs)
}
func Common(args cli.CommonArgs) flag.Applier {
return common{args}
}

// cache defines cache flags and implements Applier interface for the cache flags.
Expand All @@ -169,18 +159,8 @@ func (f cache) Apply(cmd safecli.CommandAppender) error {
}

// Cache creates a new cache flag.
// If no arguments are provided, the default cache flags are used.
// If one argument is provided, the cache flags are used.
// If more than one argument is provided, ErrInvalidCacheArgs is returned.
func Cache(args ...cli.CacheArgs) flag.Applier {
switch len(args) {
case 0:
return cache{cli.CacheArgs{}}
case 1:
return cache{args[0]}
default:
return flag.ErrorFlag(cli.ErrInvalidCacheArgs)
}
func Cache(args cli.CacheArgs) flag.Applier {
return cache{args}
}

// JSONOutput creates a new JSON output flag.
Expand Down
14 changes: 2 additions & 12 deletions pkg/kopia/cli/internal/flag/common/common_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,9 @@ var _ = check.Suite(test.NewFlagSuite([]test.FlagTest{
},
{
Name: "Empty Common should generate a flag with default value(s)",
Flag: Common(),
Flag: Common(cli.CommonArgs{}),
ExpectedCLI: []string{"--log-level=error"},
},
{
Name: "Common with more than one cli.CommonArgs should generate an error",
Flag: Common(cli.CommonArgs{}, cli.CommonArgs{}),
ExpectedErr: cli.ErrInvalidCommonArgs,
},
{
Name: "Common with values should generate multiple flags with the given values and redact password for logs",
Flag: Common(cli.CommonArgs{
Expand All @@ -149,18 +144,13 @@ var _ = check.Suite(test.NewFlagSuite([]test.FlagTest{
},
{
Name: "Empty FlagCacheArgs should generate multiple flags with default values",
Flag: Cache(),
Flag: Cache(cli.CacheArgs{}),
ExpectedCLI: []string{
"--cache-directory=/tmp/kopia-cache",
"--content-cache-size-limit-mb=0",
"--metadata-cache-size-limit-mb=0",
},
},
{
Name: "Cache with more than one cli.CacheArgs should generate an error",
Flag: Cache(cli.CacheArgs{}, cli.CacheArgs{}),
ExpectedErr: cli.ErrInvalidCacheArgs,
},
{
Name: "Cache with CacheArgs should generate multiple cache related flags",
Flag: Cache(cli.CacheArgs{
Expand Down

0 comments on commit 246e1c1

Please sign in to comment.