format tpl/main.go templates (#980)
This commit is contained in:
parent
0d9d2d46f3
commit
447f182a9d
8
cobra/cmd/testdata/root.go.golden
vendored
8
cobra/cmd/testdata/root.go.golden
vendored
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 }}
|
||||
`)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user