Skip to content

Commit

Permalink
dev: improve --presets and --out-format flags help (#5251)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
alexandear and ldez authored Dec 25, 2024
1 parent 286701c commit b4032c0
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions pkg/commands/flagsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func setupLintersFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
color.GreenString("Enable only fast linters from enabled linters set (first run won't be fast)"))

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

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

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

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

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

func formatList(head string, items []string, foot ...string) string {
parts := []string{color.GreenString(head)}
for _, p := range items {
parts = append(parts, fmt.Sprintf(" - %s", color.YellowString(p)))
}

for _, s := range foot {
parts = append(parts, color.GreenString(s))
}

if len(foot) == 0 {
parts = append(parts, "")
}

return strings.Join(parts, "\n")
}

func getDefaultIssueExcludeHelp() string {
parts := []string{color.GreenString("Use or not use default excludes:")}

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

return strings.Join(parts, "\n")
}

func getDefaultDirectoryExcludeHelp() string {
parts := []string{color.GreenString("Use or not use default excluded directories:")}
for _, dir := range processors.StdExcludeDirRegexps {
parts = append(parts, fmt.Sprintf(" - %s", color.YellowString(dir)))
}
parts = append(parts, "")
return strings.Join(parts, "\n")
}

0 comments on commit b4032c0

Please sign in to comment.