mirror of https://github.com/spf13/cobra.git
More linting (#2099)
* Address gocritic findings, enable it * Enable gosimple, no new findings to address
This commit is contained in:
parent
bd914e58d6
commit
6b5f577ebc
|
@ -29,7 +29,7 @@ linters:
|
||||||
- gas
|
- gas
|
||||||
#- gochecknoinits
|
#- gochecknoinits
|
||||||
- goconst
|
- goconst
|
||||||
#- gocritic
|
- gocritic
|
||||||
#- gocyclo
|
#- gocyclo
|
||||||
#- gofmt
|
#- gofmt
|
||||||
- goimports
|
- goimports
|
||||||
|
@ -37,7 +37,7 @@ linters:
|
||||||
#- gomnd
|
#- gomnd
|
||||||
#- goprintffuncname
|
#- goprintffuncname
|
||||||
#- gosec
|
#- gosec
|
||||||
#- gosimple
|
- gosimple
|
||||||
- govet
|
- govet
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- interfacer
|
- interfacer
|
||||||
|
|
|
@ -597,19 +597,16 @@ func writeRequiredFlag(buf io.StringWriter, cmd *Command) {
|
||||||
if nonCompletableFlag(flag) {
|
if nonCompletableFlag(flag) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for key := range flag.Annotations {
|
if _, ok := flag.Annotations[BashCompOneRequiredFlag]; ok {
|
||||||
switch key {
|
format := " must_have_one_flag+=(\"--%s"
|
||||||
case BashCompOneRequiredFlag:
|
if flag.Value.Type() != "bool" {
|
||||||
format := " must_have_one_flag+=(\"--%s"
|
format += "="
|
||||||
if flag.Value.Type() != "bool" {
|
}
|
||||||
format += "="
|
format += cbn
|
||||||
}
|
WriteStringAndCheck(buf, fmt.Sprintf(format, flag.Name))
|
||||||
format += cbn
|
|
||||||
WriteStringAndCheck(buf, fmt.Sprintf(format, flag.Name))
|
|
||||||
|
|
||||||
if len(flag.Shorthand) > 0 {
|
if len(flag.Shorthand) > 0 {
|
||||||
WriteStringAndCheck(buf, fmt.Sprintf(" must_have_one_flag+=(\"-%s"+cbn, flag.Shorthand))
|
WriteStringAndCheck(buf, fmt.Sprintf(" must_have_one_flag+=(\"-%s"+cbn, flag.Shorthand))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -2777,7 +2777,7 @@ func TestFind(t *testing.T) {
|
||||||
|
|
||||||
func TestUnknownFlagShouldReturnSameErrorRegardlessOfArgPosition(t *testing.T) {
|
func TestUnknownFlagShouldReturnSameErrorRegardlessOfArgPosition(t *testing.T) {
|
||||||
testCases := [][]string{
|
testCases := [][]string{
|
||||||
//{"--unknown", "--namespace", "foo", "child", "--bar"}, // FIXME: This test case fails, returning the error `unknown command "foo" for "root"` instead of the expected error `unknown flag: --unknown`
|
// {"--unknown", "--namespace", "foo", "child", "--bar"}, // FIXME: This test case fails, returning the error `unknown command "foo" for "root"` instead of the expected error `unknown flag: --unknown`
|
||||||
{"--namespace", "foo", "--unknown", "child", "--bar"},
|
{"--namespace", "foo", "--unknown", "child", "--bar"},
|
||||||
{"--namespace", "foo", "child", "--unknown", "--bar"},
|
{"--namespace", "foo", "child", "--unknown", "--bar"},
|
||||||
{"--namespace", "foo", "child", "--bar", "--unknown"},
|
{"--namespace", "foo", "child", "--bar", "--unknown"},
|
||||||
|
|
|
@ -133,7 +133,7 @@ func fillHeader(header *GenManHeader, name string, disableAutoGen bool) error {
|
||||||
}
|
}
|
||||||
header.Date = &now
|
header.Date = &now
|
||||||
}
|
}
|
||||||
header.date = (*header.Date).Format("Jan 2006")
|
header.date = header.Date.Format("Jan 2006")
|
||||||
if header.Source == "" && !disableAutoGen {
|
if header.Source == "" && !disableAutoGen {
|
||||||
header.Source = "Auto generated by spf13/cobra"
|
header.Source = "Auto generated by spf13/cobra"
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ func hasSeeAlso(cmd *cobra.Command) bool {
|
||||||
// that do not contain \n.
|
// that do not contain \n.
|
||||||
func forceMultiLine(s string) string {
|
func forceMultiLine(s string) string {
|
||||||
if len(s) > 60 && !strings.Contains(s, "\n") {
|
if len(s) > 60 && !strings.Contains(s, "\n") {
|
||||||
s = s + "\n"
|
s += "\n"
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@ import (
|
||||||
func genPowerShellComp(buf io.StringWriter, name string, includeDesc bool) {
|
func genPowerShellComp(buf io.StringWriter, name string, includeDesc bool) {
|
||||||
// Variables should not contain a '-' or ':' character
|
// Variables should not contain a '-' or ':' character
|
||||||
nameForVar := name
|
nameForVar := name
|
||||||
nameForVar = strings.Replace(nameForVar, "-", "_", -1)
|
nameForVar = strings.ReplaceAll(nameForVar, "-", "_")
|
||||||
nameForVar = strings.Replace(nameForVar, ":", "_", -1)
|
nameForVar = strings.ReplaceAll(nameForVar, ":", "_")
|
||||||
|
|
||||||
compCmd := ShellCompRequestCmd
|
compCmd := ShellCompRequestCmd
|
||||||
if !includeDesc {
|
if !includeDesc {
|
||||||
|
|
Loading…
Reference in New Issue