github.com/ldez/golangci-lint@v1.10.1/pkg/commands/help.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 8 "github.com/fatih/color" 9 "github.com/golangci/golangci-lint/pkg/lint/linter" 10 "github.com/golangci/golangci-lint/pkg/lint/lintersdb" 11 "github.com/golangci/golangci-lint/pkg/logutils" 12 "github.com/spf13/cobra" 13 ) 14 15 func (e *Executor) initHelp() { 16 helpCmd := &cobra.Command{ 17 Use: "help", 18 Short: "Help", 19 Run: func(cmd *cobra.Command, args []string) { 20 if err := cmd.Help(); err != nil { 21 e.log.Fatalf("Can't run help: %s", err) 22 } 23 }, 24 } 25 e.rootCmd.AddCommand(helpCmd) 26 27 lintersHelpCmd := &cobra.Command{ 28 Use: "linters", 29 Short: "Help about linters", 30 Run: e.executeLintersHelp, 31 } 32 helpCmd.AddCommand(lintersHelpCmd) 33 } 34 35 func printLinterConfigs(lcs []linter.Config) { 36 for _, lc := range lcs { 37 fmt.Fprintf(logutils.StdOut, "%s: %s [fast: %t]\n", color.YellowString(lc.Linter.Name()), 38 lc.Linter.Desc(), !lc.DoesFullImport) 39 } 40 } 41 42 func (e Executor) executeLintersHelp(cmd *cobra.Command, args []string) { 43 var enabledLCs, disabledLCs []linter.Config 44 for _, lc := range lintersdb.GetAllSupportedLinterConfigs() { 45 if lc.EnabledByDefault { 46 enabledLCs = append(enabledLCs, lc) 47 } else { 48 disabledLCs = append(disabledLCs, lc) 49 } 50 } 51 52 color.Green("Enabled by default linters:\n") 53 printLinterConfigs(enabledLCs) 54 color.Red("\nDisabled by default linters:\n") 55 printLinterConfigs(disabledLCs) 56 57 color.Green("\nLinters presets:") 58 for _, p := range lintersdb.AllPresets() { 59 linters := lintersdb.GetAllLinterConfigsForPreset(p) 60 linterNames := []string{} 61 for _, lc := range linters { 62 linterNames = append(linterNames, lc.Linter.Name()) 63 } 64 fmt.Fprintf(logutils.StdOut, "%s: %s\n", color.YellowString(p), strings.Join(linterNames, ", ")) 65 } 66 67 os.Exit(0) 68 }