Golang Command Examples

Golang Command - 30 examples found. These are the top rated real world Golang examples of github.com/spf13/cobra.Command extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
// runSetAcct invokes the REST API with POST action and key prefix as
// path. The specified configuration file is read from disk and sent
// as the POST body.
func runSetAcct(cmd *cobra.Command, args []string) {
	if len(args) != 2 {
		cmd.Usage()
		return
	}
	server.RunSetAcct(Context, args[0], args[1])
}
Example #2
0
File: hugo.go Project: nitoyon/hugo
// initCoreCommonFlags initializes common flags used by Hugo core commands.
func initCoreCommonFlags(cmd *cobra.Command) {
	cmd.Flags().StringVar(&cfgFile, "config", "", "config file (default is path/config.yaml|json|toml)")

	// Set bash-completion
	validConfigFilenames := []string{"json", "js", "yaml", "yml", "toml", "tml"}
	cmd.Flags().SetAnnotation("config", cobra.BashCompFilenameExt, validConfigFilenames)
}
Example #3
0
func serverComplexFlags(ccmd *cobra.Command) {
	serverSimpleFlags(ccmd)
	ccmd.Flags().StringVarP(&server.Forwarder, "server-forwarder", "f", "g", "Forwarder method [g i m]")
	ccmd.Flags().IntVarP(&server.Weight, "server-weight", "w", 1, "weight of down-stream server")
	ccmd.Flags().IntVarP(&server.UpperThreshold, "server-upper-threshold", "u", 0, "Upper threshold of down-stream server")
	ccmd.Flags().IntVarP(&server.LowerThreshold, "server-lower-threshold", "l", 0, "Lower threshold of down-stream server")
}
Example #4
0
func (a *Acl) AddDestroySub(c *cobra.Command) {
	destroyCmd := &cobra.Command{
		Use:   "destroy <token>",
		Short: "Destroy an ACL",
		Long:  "Destroy an ACL",
		RunE: func(cmd *cobra.Command, args []string) error {
			return a.Destroy(args)
		},
	}

	oldDestroyCmd := &cobra.Command{
		Use:        "acl-destroy <token>",
		Short:      "Destroy an ACL",
		Long:       "Destroy an ACL",
		Deprecated: "Use acl destroy",
		Hidden:     true,
		RunE: func(cmd *cobra.Command, args []string) error {
			return a.Destroy(args)
		},
	}

	c.AddCommand(destroyCmd)

	a.AddCommand(oldDestroyCmd)
}
Example #5
0
func UseOptionsTemplates(cmd *cobra.Command) {
	cmd.SetHelpTemplate(OptionsHelpTemplate())
	templater := &templater{
		UsageTemplate: OptionsUsageTemplate(),
	}
	cmd.SetUsageFunc(templater.UsageFunc())
}
Example #6
0
func GetFlagBool(cmd *cobra.Command, flag string) bool {
	b, err := cmd.Flags().GetBool(flag)
	if err != nil {
		glog.Fatalf("err accessing flag %s for command %s: %v", flag, cmd.Name(), err)
	}
	return b
}