Skip to content

Commit 92a5753

Browse files
committed
dev: improve --presets and --out-format flags help
1 parent 0b08f09 commit 92a5753

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

pkg/commands/flagsets.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ func setupLintersFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
2727
internal.AddFlagAndBind(v, fs, fs.Bool, "fast", "linters.fast", false,
2828
color.GreenString("Enable only fast linters from enabled linters set (first run won't be fast)"))
2929

30-
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"+
33-
"This option implies option --disable-all",
34-
strings.Join(lintersdb.AllPresets(), "|"),
35-
)))
30+
internal.AddHackedStringSliceP(fs, "presets", "p", getPresetsHelp())
3631

3732
fs.StringSlice("enable-only", nil,
3833
color.GreenString("Override linters configuration section to only run the specific linter(s)")) // Flags only.
@@ -68,8 +63,7 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
6863
}
6964

7065
func setupOutputFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
71-
internal.AddFlagAndBind(v, fs, fs.String, "out-format", "output.formats", config.OutFormatColoredLineNumber,
72-
color.GreenString(fmt.Sprintf("Formats of output: %s", strings.Join(config.AllOutputFormats, "|"))))
66+
internal.AddFlagAndBind(v, fs, fs.String, "out-format", "output.formats", config.OutFormatColoredLineNumber, getOutFormatHelp())
7367
internal.AddFlagAndBind(v, fs, fs.Bool, "print-issued-lines", "output.print-issued-lines", true,
7468
color.GreenString("Print lines of code with issue"))
7569
internal.AddFlagAndBind(v, fs, fs.Bool, "print-linter-name", "output.print-linter-name", true,
@@ -123,6 +117,25 @@ func setupIssuesFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
123117
color.GreenString("Fix found issues (if it's supported by the linter)"))
124118
}
125119

120+
func getPresetsHelp() string {
121+
parts := []string{color.GreenString("Enable presets of linters:")}
122+
for _, p := range lintersdb.AllPresets() {
123+
parts = append(parts, fmt.Sprintf(" - %s", color.YellowString(p)))
124+
}
125+
parts = append(parts, color.GreenString("Run 'golangci-lint help linters' to see them."),
126+
color.GreenString("This option implies option --disable-all"))
127+
return strings.Join(parts, "\n")
128+
}
129+
130+
func getOutFormatHelp() string {
131+
parts := []string{color.GreenString("Formats of output:")}
132+
for _, f := range config.AllOutputFormats {
133+
parts = append(parts, fmt.Sprintf(" - %s", color.YellowString(f)))
134+
}
135+
parts = append(parts, "")
136+
return strings.Join(parts, "\n")
137+
}
138+
126139
func getDefaultIssueExcludeHelp() string {
127140
parts := []string{color.GreenString("Use or not use default excludes:")}
128141

0 commit comments

Comments
 (0)