Skip to content
Myr

cmd: Add possibility to specify the target package

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #455

authored by Albert Nigmatzianov · committed by Albert Nigmatzianov · parent 84f4716 · Browse files · 2 files+14 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−8 removed

  • other:+14 added−8 removed

2 files+14 added−8 removed

modified:cobra/cmd/add.go+12 added-5 removed
21 unmodified lines
22 "github.com/spf13/cobra"23)2425func init() {26 addCmd.Flags().StringVarP(&packageName, "package", "t", "", "target package name (e.g. github.com/spf13/hugo)")27 addCmd.Flags().StringVarP(&parentName, "parent", "p", "RootCmd", "name of parent command for this command")28}2929var parentName string30var packageName, parentName string3132var addCmd = &cobra.Command{33 Use: "add [command name]",34 Aliases: []string{"command"},
10 unmodified lines
45 Run: func(cmd *cobra.Command, args []string) {46 if len(args) < 1 {47 er("add needs a name for the command")48 }4950 var project *Project51 if packageName != "" {52 project = NewProject(packageName)53 } else {48 wd, err := os.Getwd()49 if err != nil {50 er(err)54 wd, err := os.Getwd()55 if err != nil {56 er(err)57 }58 project = NewProjectFromPath(wd)59 }52 project := NewProjectFromPath(wd)6061 cmdName := validateCmdName(args[0])62 cmdPath := filepath.Join(project.CmdPath(), cmdName+".go")63 createCmdFile(project.License(), cmdPath, cmdName)
116 unmodified lines
modified:cobra/cmd/root.go+2 added-3 removed
42 unmodified lines
43 initViper()4445 rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")46 rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "author name for copyright attribution")47 rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project (can provide `license` in config)")47 rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project")48 rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration")49 viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author"))50 viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper"))51 viper.SetDefault("author", "NAME HERE <EMAIL ADDRESS>")52 viper.SetDefault("license", "apache")5354 rootCmd.AddCommand(initCmd)54 rootCmd.AddCommand(addCmd)5655 rootCmd.AddCommand(initCmd)56}5758func initViper() {59 if cfgFile != "" {
20 unmodified lines