Skip to content

Commit b4032c0

Browse files
alexandearldez
andauthored
dev: improve --presets and --out-format flags help (#5251)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent 286701c commit b4032c0

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

pkg/commands/flagsets.go

+24-16
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ func setupLintersFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
2828
color.GreenString("Enable only fast linters from enabled linters set (first run won't be fast)"))
2929

3030
internal.AddHackedStringSliceP(fs, "presets", "p",
31-
color.GreenString(fmt.Sprintf("Enable presets (%s) of linters.\n"+
32-
"Run 'golangci-lint help linters' to see them.\n"+
31+
formatList("Enable presets of linters:", lintersdb.AllPresets(),
32+
"Run 'golangci-lint help linters' to see them.",
3333
"This option implies option --disable-all",
34-
strings.Join(lintersdb.AllPresets(), "|"),
35-
)))
34+
),
35+
)
3636

3737
fs.StringSlice("enable-only", nil,
3838
color.GreenString("Override linters configuration section to only run the specific linter(s)")) // Flags only.
@@ -57,7 +57,7 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
5757
internal.AddDeprecatedHackedStringSlice(fs, "skip-files", color.GreenString("Regexps of files to skip"))
5858
internal.AddDeprecatedHackedStringSlice(fs, "skip-dirs", color.GreenString("Regexps of directories to skip"))
5959
internal.AddDeprecatedFlagAndBind(v, fs, fs.Bool, "skip-dirs-use-default", "run.skip-dirs-use-default", true,
60-
getDefaultDirectoryExcludeHelp())
60+
formatList("Use or not use default excluded directories:", processors.StdExcludeDirRegexps))
6161

6262
const allowParallelDesc = "Allow multiple parallel golangci-lint instances running.\n" +
6363
"If false (default) - golangci-lint acquires file lock on start."
@@ -70,7 +70,7 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
7070

7171
func setupOutputFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
7272
internal.AddFlagAndBind(v, fs, fs.String, "out-format", "output.formats", config.OutFormatColoredLineNumber,
73-
color.GreenString(fmt.Sprintf("Formats of output: %s", strings.Join(config.AllOutputFormats, "|"))))
73+
formatList("Formats of output:", config.AllOutputFormats))
7474
internal.AddFlagAndBind(v, fs, fs.Bool, "print-issued-lines", "output.print-issued-lines", true,
7575
color.GreenString("Print lines of code with issue"))
7676
internal.AddFlagAndBind(v, fs, fs.Bool, "print-linter-name", "output.print-linter-name", true,
@@ -102,7 +102,7 @@ func setupIssuesFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
102102
internal.AddHackedStringSlice(fs, "exclude-files", color.GreenString("Regexps of files to exclude"))
103103
internal.AddHackedStringSlice(fs, "exclude-dirs", color.GreenString("Regexps of directories to exclude"))
104104
internal.AddFlagAndBind(v, fs, fs.Bool, "exclude-dirs-use-default", "issues.exclude-dirs-use-default", true,
105-
getDefaultDirectoryExcludeHelp())
105+
formatList("Use or not use default excluded directories:", processors.StdExcludeDirRegexps))
106106

107107
internal.AddFlagAndBind(v, fs, fs.String, "exclude-generated", "issues.exclude-generated", processors.AutogeneratedModeLax,
108108
color.GreenString("Mode of the generated files analysis"))
@@ -124,6 +124,23 @@ func setupIssuesFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
124124
color.GreenString("Fix found issues (if it's supported by the linter)"))
125125
}
126126

127+
func formatList(head string, items []string, foot ...string) string {
128+
parts := []string{color.GreenString(head)}
129+
for _, p := range items {
130+
parts = append(parts, fmt.Sprintf(" - %s", color.YellowString(p)))
131+
}
132+
133+
for _, s := range foot {
134+
parts = append(parts, color.GreenString(s))
135+
}
136+
137+
if len(foot) == 0 {
138+
parts = append(parts, "")
139+
}
140+
141+
return strings.Join(parts, "\n")
142+
}
143+
127144
func getDefaultIssueExcludeHelp() string {
128145
parts := []string{color.GreenString("Use or not use default excludes:")}
129146

@@ -136,12 +153,3 @@ func getDefaultIssueExcludeHelp() string {
136153

137154
return strings.Join(parts, "\n")
138155
}
139-
140-
func getDefaultDirectoryExcludeHelp() string {
141-
parts := []string{color.GreenString("Use or not use default excluded directories:")}
142-
for _, dir := range processors.StdExcludeDirRegexps {
143-
parts = append(parts, fmt.Sprintf(" - %s", color.YellowString(dir)))
144-
}
145-
parts = append(parts, "")
146-
return strings.Join(parts, "\n")
147-
}

0 commit comments

Comments
 (0)