github.com/lenfree/buffalo@v0.7.3-0.20170207163156-891616ea4064/buffalo/cmd/root.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"os/exec"
     7  
     8  	"github.com/gobuffalo/buffalo/buffalo/cmd/generate"
     9  	"github.com/spf13/cobra"
    10  )
    11  
    12  var cfgFile string
    13  
    14  // RootCmd is the hook for all of the other commands in the buffalo binary.
    15  var RootCmd = &cobra.Command{
    16  	SilenceErrors: true,
    17  	Use:           "buffalo",
    18  	Short:         "Helps you build your Buffalo applications that much easier!",
    19  	PersistentPreRun: func(cmd *cobra.Command, args []string) {
    20  		fmt.Printf("Buffalo version %s\n\n", Version)
    21  	},
    22  }
    23  
    24  // Execute adds all child commands to the root command sets flags appropriately.
    25  // This is called by main.main(). It only needs to happen once to the rootCmd.
    26  func Execute() {
    27  	if err := RootCmd.Execute(); err != nil {
    28  		fmt.Printf("Error: %s\n\n", err)
    29  		os.Exit(-1)
    30  	}
    31  }
    32  
    33  func goInstall(pkg string) *exec.Cmd {
    34  	return generate.GoInstall(pkg)
    35  }
    36  
    37  func goGet(pkg string) *exec.Cmd {
    38  	return generate.GoGet(pkg)
    39  }
    40  
    41  // func init() {
    42  // cobra.OnInitialize(initConfig)
    43  // RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.buffalo.yaml)")
    44  // }
    45  
    46  // func initConfig() {
    47  // 	if cfgFile != "" { // enable ability to specify config file via flag
    48  // 		viper.SetConfigFile(cfgFile)
    49  // 	}
    50  //
    51  // 	viper.SetConfigName(".buffalo") // name of config file (without extension)
    52  // 	viper.AddConfigPath("$HOME")    // adding home directory as first search path
    53  // 	viper.AutomaticEnv()            // read in environment variables that match
    54  //
    55  // 	// If a config file is found, read it in.
    56  // 	if err := viper.ReadInConfig(); err == nil {
    57  // 		fmt.Println("Using config file:", viper.ConfigFileUsed())
    58  // 	}
    59  // }