add command 'golangci-lint config path'
This commit is contained in:
parent
cb5d1da986
commit
27752e81a7
51
pkg/commands/config.go
Normal file
51
pkg/commands/config.go
Normal file
@ -0,0 +1,51 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/exitcodes"
|
||||
"github.com/golangci/golangci-lint/pkg/fsutils"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func (e *Executor) initConfig() {
|
||||
cmd := &cobra.Command{
|
||||
Use: "config",
|
||||
Short: "Config",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := cmd.Help(); err != nil {
|
||||
e.log.Fatalf("Can't run help: %s", err)
|
||||
}
|
||||
},
|
||||
}
|
||||
e.rootCmd.AddCommand(cmd)
|
||||
|
||||
pathCmd := &cobra.Command{
|
||||
Use: "path",
|
||||
Short: "Print used config path",
|
||||
Run: e.executePathCmd,
|
||||
}
|
||||
e.initRunConfiguration(pathCmd) // allow --config
|
||||
cmd.AddCommand(pathCmd)
|
||||
|
||||
}
|
||||
|
||||
func (e Executor) executePathCmd(cmd *cobra.Command, args []string) {
|
||||
usedConfigFile := viper.ConfigFileUsed()
|
||||
if usedConfigFile == "" {
|
||||
e.log.Warnf("No config file detected")
|
||||
os.Exit(exitcodes.NoConfigFileDetected)
|
||||
}
|
||||
|
||||
usedConfigFile, err := fsutils.ShortestRelPath(usedConfigFile, "")
|
||||
if err != nil {
|
||||
e.log.Warnf("Can't pretty print config file path: %s", err)
|
||||
}
|
||||
|
||||
fmt.Println(usedConfigFile)
|
||||
os.Exit(0)
|
||||
}
|
@ -55,6 +55,7 @@ func NewExecutor(version, commit, date string) *Executor {
|
||||
e.initRun()
|
||||
e.initHelp()
|
||||
e.initLinters()
|
||||
e.initConfig()
|
||||
|
||||
// init e.cfg by values from config: flags parse will see these values
|
||||
// like the default ones. It will overwrite them only if the same option
|
||||
|
@ -22,7 +22,7 @@ func (e *Executor) initHelp() {
|
||||
}
|
||||
},
|
||||
}
|
||||
e.rootCmd.AddCommand(helpCmd)
|
||||
e.rootCmd.SetHelpCommand(helpCmd)
|
||||
|
||||
lintersHelpCmd := &cobra.Command{
|
||||
Use: "linters",
|
||||
|
@ -1,12 +1,13 @@
|
||||
package exitcodes
|
||||
|
||||
const (
|
||||
Success = 0
|
||||
IssuesFound = 1
|
||||
WarningInTest = 2
|
||||
Failure = 3
|
||||
Timeout = 4
|
||||
NoGoFiles = 5
|
||||
Success = 0
|
||||
IssuesFound = 1
|
||||
WarningInTest = 2
|
||||
Failure = 3
|
||||
Timeout = 4
|
||||
NoGoFiles = 5
|
||||
NoConfigFileDetected = 6
|
||||
)
|
||||
|
||||
type ExitError struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user