// New returns a new root Cobra cmd with some default flags and graceful stopping
New returns a new root Cobra cmd with some default flags and graceful stopping
// New returns a new root Cobra cmd with some default flags and graceful stopping
func New(programName string) *cobra.Command {
	stop = make(chan os.Signal)
	rootCmd := &cobra.Command{
		Use:   programName,
		Short: "",
		Long:  "",
		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
			signal.Notify(stop, syscall.SIGTERM)
			signal.Notify(stop, syscall.SIGINT)
			return nil
		},
		PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
			plugin.Close()
			return nil
		},
		Version: BuildVersion,
	}
	viper.AutomaticEnv()
	viper.SetConfigName(programName)
	viper.SetConfigType("yaml")
	rootCmd.Flags().String(flagNetworkAddress, "tcp://:8080", "the network address to listen on e.g. unix:///var/run/test.sock or tcp://:8080")
	if err := viper.BindPFlag(flagNetworkAddress, rootCmd.Flags().Lookup(flagNetworkAddress)); err != nil {
		HandleErr(err)
	}
	err := plugin.LoadPluginsFromConfigSlice(viper.GetStringSlice("plugins"))
	if err != nil {
		HandleErr(err)
	}
	if err := LoadPlugins(rootCmd); err != nil {
		HandleErr(err)
	}
	return rootCmd
}
func New ( programName string ) * cobra . Command { stop = make ( chan os . Signal ) rootCmd := & cobra . Command { Use : programName , Short : " " , Long : " " , PersistentPreRunE : func ( cmd * cobra . Command , args [ ] string ) error { signal . Notify ( stop , syscall . SIGTERM ) signal . Notify ( stop , syscall . SIGINT ) return nil } , PersistentPostRunE : func ( cmd * cobra . Command , args [ ] string ) error { plugin . Close ( ) return nil } , Version : BuildVersion , } viper . AutomaticEnv ( ) viper . SetConfigName ( programName ) viper . SetConfigType ( " " ) rootCmd . Flags ( ) . String ( flagNetworkAddress , " " , " " ) if err := viper . BindPFlag ( flagNetworkAddress , rootCmd . Flags ( ) . Lookup ( flagNetworkAddress ) ) ; err != nil { HandleErr ( err ) } err := plugin . LoadPluginsFromConfigSlice ( viper . GetStringSlice ( " " ) ) if err != nil { HandleErr ( err ) } if err := LoadPlugins ( rootCmd ) ; err != nil { HandleErr ( err ) } return rootCmd }
New returns a new root Cobra cmd with some default flags and graceful stopping
New returns a new root Cobra cmd with some default flags and graceful stopping
// set up interrupts // rootCmd.Flags().String(flagConfigPath, ".", "the path to look for configuration yamls in") // viper.BindPFlag(flagConfigPath, rootCmd.Flags().Lookup(flagConfigPath)) // load plugins and add plugin flags