Skip to content

Commit 440e768

Browse files
gharleyglyn
authored andcommitted
Remove unused functions from commands package
* Functions NotSet, FlagValidName, and NoneOf deleted from cmd/commands/cobra.go
1 parent 4cd44be commit 440e768

File tree

1 file changed

+2
-40
lines changed

1 file changed

+2
-40
lines changed

cmd/commands/cobra.go

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,6 @@ func Set(name string) FlagsMatcher {
159159
}
160160
}
161161

162-
func NotSet(name string) FlagsMatcher {
163-
return flagsMatcher{
164-
eval: func(cmd *cobra.Command) bool {
165-
f := cmd.Flag(name)
166-
if f == nil {
167-
panic(fmt.Sprintf("Expected to find flag named %q in command %q", name, cmd.Use))
168-
}
169-
return !f.Changed
170-
},
171-
desc: fmt.Sprintf("--%s is not set", name),
172-
}
173-
}
174-
175162
// FlagsDependency returns a validator that will evaluate the given delegate if the provided flag matcher returns true.
176163
// Use to enforce scenarios such as "if --foo is set, then --bar must be set as well".
177164
func FlagsDependency(matcher FlagsMatcher, delegate FlagsValidator) FlagsValidator {
@@ -237,15 +224,6 @@ func NotBlank(flagName string) FlagsValidator {
237224
}
238225
}
239226

240-
func FlagValidName(flagName string) FlagsValidator {
241-
return func(cmd *cobra.Command) error {
242-
if errs := validation.IsDNS1123Subdomain(cmd.Flag(flagName).Value.String()); len(errs) > 0 {
243-
return fmt.Errorf("invalid registry hostname: %s", strings.Join(errs, "; "))
244-
}
245-
return nil
246-
}
247-
}
248-
249227
// ExactlyOneOf returns a FlagsValidator that asserts that one and only one of the passed in flags is set.
250228
func ExactlyOneOf(flagNames ...string) FlagsValidator {
251229
return FlagsValidationConjunction(
@@ -254,22 +232,6 @@ func ExactlyOneOf(flagNames ...string) FlagsValidator {
254232
)
255233
}
256234

257-
// NoneOf returns a FlagsValidator that asserts that none of the passed in flags are set.
258-
func NoneOf(flagNames ...string) FlagsValidator {
259-
return func(cmd *cobra.Command) error {
260-
for _, f := range flagNames {
261-
flag := cmd.Flag(f)
262-
if flag == nil {
263-
panic(fmt.Sprintf("Expected to find flag named %q in command %q", f, cmd.Use))
264-
}
265-
if flag.Changed {
266-
return fmt.Errorf("--%s should not be set", f)
267-
}
268-
}
269-
return nil
270-
}
271-
}
272-
273235
// =========================================== Usage related functions =================================================
274236

275237
func installAdvancedUsage(rootCmd *cobra.Command) {
@@ -325,8 +287,8 @@ func tmpl(w io.Writer, text string, data interface{}) error {
325287

326288
// rpad adds padding to the right of a string.
327289
func rpad(s string, padding int) string {
328-
template := fmt.Sprintf("%%-%ds", padding)
329-
return fmt.Sprintf(template, s)
290+
format := fmt.Sprintf("%%-%ds", padding)
291+
return fmt.Sprintf(format, s)
330292
}
331293

332294
func trimRightSpace(s string) string {

0 commit comments

Comments
 (0)