format tpl/main.go templates (#980)

This commit is contained in:
Joshua Harshman 2019-12-23 13:51:40 -07:00 committed by GitHub
parent 0d9d2d46f3
commit 447f182a9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 92 additions and 99 deletions

View file

@ -17,18 +17,15 @@ package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"os"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
)
var cfgFile string
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "testproject",
@ -62,13 +59,11 @@ func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.testproject.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
@ -94,4 +89,3 @@ func initConfig() {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
}

View file

@ -24,17 +24,17 @@ package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"os"
{{ if .Viper }}
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
{{ end }}
{{ end -}}
)
{{ if .Viper }}
{{ if .Viper -}}
var cfgFile string
{{ end }}
{{- end }}
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
@ -72,13 +72,12 @@ func init() {
{{ else }}
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.{{ .AppName }}.yaml)")
{{ end }}
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
{{ if .Viper }}
{{ if .Viper -}}
// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
@ -104,7 +103,7 @@ func initConfig() {
fmt.Println("Using config file:", viper.ConfigFileUsed())
}
}
{{ end }}
{{- end }}
`)
}