func initConfig() {
	if cfgFile != "" {
		viper.SetConfigFile(cfgFile)
	} else {
		home, err := homedir.Dir()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		viper.AddConfigPath(home)
		viper.SetConfigName(".jql")
	}
	viper.AutomaticEnv()  
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	}
}
initConfig reads in config file and ENV variables if set.
package cmd
import (
	"bufio"
	"encoding/json"
	"fmt"
	"log"
	"os"
	homedir "github.com/mitchellh/go-homedir"
	"github.com/nwidger/jsoncolor"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
	"github.com/cube2222/jql/jql/app"
)
var (
	cfgFile    string
	monochrome bool
)
type encoder interface {
	Encode(v interface{}) error
	SetIndent(prefix, indent string)
}
var rootCmd = &cobra.Command{
	Use:   "jql <query>",
	Short: "JSON Query Processor with a Lispy syntax.",
	Long:  string(MustAsset("../README.md")),
	Args:  cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		input := json.NewDecoder(bufio.NewReaderSize(os.Stdin, 4096*16))
		w := bufio.NewWriterSize(os.Stdout, 4096*16)
		defer w.Flush()
		var output encoder
		if monochrome {
			output = json.NewEncoder(w)
		} else {
			output = jsoncolor.NewEncoder(w)
		}
		output.SetIndent("", "  ")
		if len(args) == 0 {
			args = append(args, "(id)")
		}
		app := app.NewApp(args[0], input, output)
		if err := app.Run(); err != nil {
			log.Fatal(err)
		}
	},
}
func Execute() {
	if err := rootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
func init() {
	cobra.OnInitialize(initConfig)
	rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.jql.yaml)")
	rootCmd.PersistentFlags().BoolVar(&monochrome, "monochrome", false, "monochrome (don't colorize output)")
}