@ -23,10 +23,11 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
 | 
						addCmd.Flags().StringVarP(&packageName, "package", "t", "", "target package name (e.g. github.com/spf13/hugo)")
 | 
				
			||||||
	addCmd.Flags().StringVarP(&parentName, "parent", "p", "RootCmd", "name of parent command for this command")
 | 
						addCmd.Flags().StringVarP(&parentName, "parent", "p", "RootCmd", "name of parent command for this command")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var parentName string
 | 
					var packageName, parentName string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var addCmd = &cobra.Command{
 | 
					var addCmd = &cobra.Command{
 | 
				
			||||||
	Use:     "add [command name]",
 | 
						Use:     "add [command name]",
 | 
				
			||||||
@ -45,11 +46,17 @@ Example: cobra add server -> resulting in a new cmd/server.go`,
 | 
				
			|||||||
		if len(args) < 1 {
 | 
							if len(args) < 1 {
 | 
				
			||||||
			er("add needs a name for the command")
 | 
								er("add needs a name for the command")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var project *Project
 | 
				
			||||||
 | 
							if packageName != "" {
 | 
				
			||||||
 | 
								project = NewProject(packageName)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
			wd, err := os.Getwd()
 | 
								wd, err := os.Getwd()
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				er(err)
 | 
									er(err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		project := NewProjectFromPath(wd)
 | 
								project = NewProjectFromPath(wd)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		cmdName := validateCmdName(args[0])
 | 
							cmdName := validateCmdName(args[0])
 | 
				
			||||||
		cmdPath := filepath.Join(project.CmdPath(), cmdName+".go")
 | 
							cmdPath := filepath.Join(project.CmdPath(), cmdName+".go")
 | 
				
			||||||
 | 
				
			|||||||
@ -44,16 +44,15 @@ func init() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")
 | 
						rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")
 | 
				
			||||||
	rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "author name for copyright attribution")
 | 
						rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "author name for copyright attribution")
 | 
				
			||||||
	rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project (can provide `license` in config)")
 | 
						rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project")
 | 
				
			||||||
	rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration")
 | 
						rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration")
 | 
				
			||||||
	viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author"))
 | 
						viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author"))
 | 
				
			||||||
	viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper"))
 | 
						viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper"))
 | 
				
			||||||
	viper.SetDefault("author", "NAME HERE <EMAIL ADDRESS>")
 | 
						viper.SetDefault("author", "NAME HERE <EMAIL ADDRESS>")
 | 
				
			||||||
	viper.SetDefault("license", "apache")
 | 
						viper.SetDefault("license", "apache")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rootCmd.AddCommand(initCmd)
 | 
					 | 
				
			||||||
	rootCmd.AddCommand(addCmd)
 | 
						rootCmd.AddCommand(addCmd)
 | 
				
			||||||
 | 
						rootCmd.AddCommand(initCmd)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func initViper() {
 | 
					func initViper() {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user