本文整理汇总了Golang中github.com/spf13/cobra.Command.UsageFunc方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.UsageFunc方法的具体用法?Golang Command.UsageFunc怎么用?Golang Command.UsageFunc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spf13/cobra.Command
的用法示例。
在下文中一共展示了Command.UsageFunc方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: hostannouncecmd
// hostannouncecmd is the handler for the command `siac host announce`.
// Announces yourself as a host to the network. Optionally takes an address to
// announce as.
func hostannouncecmd(cmd *cobra.Command, args []string) {
var err error
switch len(args) {
case 0:
err = post("/host/announce", "")
case 1:
err = post("/host/announce", "netaddress="+args[0])
default:
cmd.UsageFunc()(cmd)
os.Exit(exitCodeUsage)
}
if err != nil {
die("Could not announce host:", err)
}
fmt.Println("Host announcement submitted to network.")
// start accepting contracts
err = post("/host", "acceptingcontracts=true")
if err != nil {
die("Could not configure host to accept contracts:", err)
}
fmt.Println(`
The host has also been configured to accept contracts.
To revert this, run:
siac host config acceptingcontracts false
`)
}
示例2: CommandFor
// CommandFor returns the appropriate command for this base name,
// or the OpenShift CLI command.
func CommandFor(basename string) *cobra.Command {
var cmd *cobra.Command
out := os.Stdout
// Make case-insensitive and strip executable suffix if present
if runtime.GOOS == "windows" {
basename = strings.ToLower(basename)
basename = strings.TrimSuffix(basename, ".exe")
}
switch basename {
case "kubectl":
cmd = NewCmdKubectl(basename, out)
default:
cmd = NewCommandCLI(basename, basename, out)
}
if cmd.UsageFunc() == nil {
templates.ActsAsRootCommand(cmd)
}
flagtypes.GLog(cmd.PersistentFlags())
return cmd
}
示例3: delete
func delete(cmd *cobra.Command, args []string) {
url := cmd.Flag("registry").Value.String()
if len(args) != 1 {
cmd.UsageFunc()(cmd)
return
}
delimg := args[0]
conn, err := connect(cmd)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
images, err := catalog(conn, url)
for _, name := range images {
tags, err := tags(conn, url, name)
if err != nil {
fmt.Fprintln(os.Stderr, err)
continue
}
for _, tag := range tags {
if strings.Compare(delimg, name+":"+tag) == 0 {
digest, _, err := manifest(conn, url, name, tag)
if err != nil {
fmt.Fprintf(os.Stderr, "manifest: %v\n", err)
return
}
err = deleteImage(conn, url, name, digest)
if err != nil {
fmt.Fprintf(os.Stderr, "delete: %v\n", err)
return
}
fmt.Printf("deleted %s:%s\n", name, tag)
return
}
}
}
}
示例4: CommandFor
// CommandFor returns the appropriate command for this base name,
// or the global OpenShift command
func CommandFor(basename string) *cobra.Command {
var cmd *cobra.Command
in, out, errout := os.Stdin, os.Stdout, os.Stderr
// Make case-insensitive and strip executable suffix if present
if runtime.GOOS == "windows" {
basename = strings.ToLower(basename)
basename = strings.TrimSuffix(basename, ".exe")
}
switch basename {
case "openshift-router":
cmd = irouter.NewCommandTemplateRouter(basename)
case "openshift-f5-router":
cmd = irouter.NewCommandF5Router(basename)
case "openshift-deploy":
cmd = deployer.NewCommandDeployer(basename)
case "openshift-recycle":
cmd = recycle.NewCommandRecycle(basename, out)
case "openshift-sti-build":
cmd = builder.NewCommandSTIBuilder(basename)
case "openshift-docker-build":
cmd = builder.NewCommandDockerBuilder(basename)
case "oc", "osc":
cmd = cli.NewCommandCLI(basename, basename, in, out, errout)
case "oadm", "osadm":
cmd = admin.NewCommandAdmin(basename, basename, out, errout)
case "kubectl":
cmd = cli.NewCmdKubectl(basename, out)
case "kube-apiserver":
cmd = kubernetes.NewAPIServerCommand(basename, basename, out)
case "kube-controller-manager":
cmd = kubernetes.NewControllersCommand(basename, basename, out)
case "kubelet":
cmd = kubernetes.NewKubeletCommand(basename, basename, out)
case "kube-proxy":
cmd = kubernetes.NewProxyCommand(basename, basename, out)
case "kube-scheduler":
cmd = kubernetes.NewSchedulerCommand(basename, basename, out)
case "kubernetes":
cmd = kubernetes.NewCommand(basename, basename, out)
case "origin", "atomic-enterprise":
cmd = NewCommandOpenShift(basename)
default:
cmd = NewCommandOpenShift("openshift")
}
if cmd.UsageFunc() == nil {
templates.ActsAsRootCommand(cmd, []string{"options"})
}
flagtypes.GLog(cmd.PersistentFlags())
return cmd
}
示例5: CommandFor
// CommandFor returns the appropriate command for this base name,
// or the global OpenShift command
func CommandFor(basename string) *cobra.Command {
var cmd *cobra.Command
out := os.Stdout
// Make case-insensitive and strip executable suffix if present
if runtime.GOOS == "windows" {
basename = strings.ToLower(basename)
basename = strings.TrimSuffix(basename, ".exe")
}
switch basename {
case "atomic-enterprise-router":
cmd = irouter.NewCommandTemplateRouter(basename)
case "atomic-enterprise-deploy":
cmd = deployer.NewCommandDeployer(basename)
case "atomic-enterprise-gitserver":
cmd = gitserver.NewCommandGitServer(basename)
case "oc", "osc":
cmd = cli.NewCommandCLI(basename, basename)
case "oadm", "osadm":
cmd = admin.NewCommandAdmin(basename, basename, out)
case "kubectl":
cmd = cli.NewCmdKubectl(basename, out)
case "kube-apiserver":
cmd = kubernetes.NewAPIServerCommand(basename, basename, out)
case "kube-controller-manager":
cmd = kubernetes.NewControllersCommand(basename, basename, out)
case "kubelet":
cmd = kubernetes.NewKubeletCommand(basename, basename, out)
case "kube-proxy":
cmd = kubernetes.NewProxyCommand(basename, basename, out)
case "kube-scheduler":
cmd = kubernetes.NewSchedulerCommand(basename, basename, out)
case "kubernetes":
cmd = kubernetes.NewCommand(basename, basename, out)
case "origin":
cmd = NewCommandAtomicEnterprise("origin")
default:
cmd = NewCommandAtomicEnterprise("atomic-enterprise")
}
if cmd.UsageFunc() == nil {
templates.ActsAsRootCommand(cmd)
}
flagtypes.GLog(cmd.PersistentFlags())
return cmd
}
示例6: Usage
func Usage(c *cobra.Command) func() error {
return func() error {
return c.UsageFunc()(c)
}
}
示例7: ConsoleErr
func ConsoleErr(cmd *cobra.Command, str string) {
cmd.Printf(str)
cmd.Println("")
cmd.UsageFunc()(cmd)
os.Exit(1)
}