David López d9a1bdb831 gocritic: fix code to pass newly added gocritic checks
Fix code to pass newly added gocritic checks, mainly pointer receivers and import shadows
2019-01-08 09:59:24 +03:00

52 lines
1.1 KiB
Go

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)
}