本文整理汇总了Golang中github.com/spf13/cobra.Command.HelpFunc方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.HelpFunc方法的具体用法?Golang Command.HelpFunc怎么用?Golang Command.HelpFunc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spf13/cobra.Command
的用法示例。
在下文中一共展示了Command.HelpFunc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: validateContainerState
func validateContainerState(cmd *cobra.Command, args []string) {
containerID, _ := cmd.Flags().GetString("id")
if len(containerID) == 0 {
cmd.HelpFunc()
return
}
//FIXME: Instead of default as linux, detect os
targetOS := "linux"
plugin, err := plugin.NewPlugin(targetOS)
if err != nil {
log.Error(err)
//fmt.Println(err)
return
}
errors, valid := plugin.ValidatePluginState(containerID)
if !valid {
for _, err := range errors {
//fmt.Println(err)
log.Warn(err)
}
fmt.Printf("\nInvalid OCI State format\n")
} else {
fmt.Println("Container State Valid OCI")
}
return
}
示例2: validateContainerConfig
func validateContainerConfig(cmd *cobra.Command, args []string) {
imagePath, _ := cmd.Flags().GetString("image")
targetOS, _ := cmd.Flags().GetString("os")
_, err := os.Stat(imagePath)
if os.IsNotExist(err) {
cmd.HelpFunc()
return
}
//FIXME: Instead of default as linux, detect os
plugin, err := plugin.NewPlugin(targetOS)
if err != nil {
//fmt.Println(err)
log.Error(err)
return
}
errors, valid := plugin.ValidatePluginSpecs(imagePath)
if !valid {
fmt.Println("")
for _, err := range errors {
log.Warn(err)
//fmt.Println(err)
}
fmt.Printf("\nInvalid OCI config format\n")
} else {
fmt.Printf("\nConfig is Valid OCI\n")
}
return
}
示例3: cmdHostname
func cmdHostname(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Printf("%s", MyAPIGet("hostname"))
} else if len(args) == 1 {
MyAPIPost("hostname", args[0])
} else {
cmd.HelpFunc()
}
}
示例4: cmdDockerBip
func cmdDockerBip(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println(MyAPIGet("docker/bip"))
} else if len(args) == 1 {
MyAPIPost("docker/bip", args[0])
} else {
cmd.HelpFunc()
}
}
示例5: preFlight
func preFlight(ccmd *cobra.Command, args []string) error {
if config.Version {
return fmt.Errorf(fmt.Sprintf("portal %s (%s)", tag, commit))
}
if !config.Server {
ccmd.HelpFunc()(ccmd, args)
return fmt.Errorf("") // no error, just exit
}
return nil
}
示例6: preFlight
func preFlight(ccmd *cobra.Command, args []string) error {
if config.Version {
fmt.Printf("logvac %s (%s)\n", tag, commit)
return fmt.Errorf("")
}
if !config.Server {
ccmd.HelpFunc()(ccmd, args)
return fmt.Errorf("")
}
return nil
}
示例7: preFlight
func preFlight(ccmd *cobra.Command, args []string) error {
if version {
fmt.Printf("pulse %s (%s)\n", tag, commit)
return fmt.Errorf("") // no error, just exit
}
if !viper.GetBool("server") {
ccmd.HelpFunc()(ccmd, args)
return fmt.Errorf("") // no error, just exit
}
return nil
}
示例8: preFlight
func preFlight(ccmd *cobra.Command, args []string) error {
// if --version is passed print the version info
if showVers {
fmt.Printf("hoarder %s (%s)\n", version, commit)
return fmt.Errorf("")
}
// if --server is not passed, print help
if !viper.GetBool("server") {
ccmd.HelpFunc()(ccmd, args)
return fmt.Errorf("") // no error, just exit
}
return nil
}
示例9: ExecAnnactlControlLogResetLevelsCmd
func (a *annactl) ExecAnnactlControlLogResetLevelsCmd(cmd *cobra.Command, args []string) {
a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnactlControlLogResetLevelsCmd")
if len(args) > 0 {
cmd.HelpFunc()(cmd, nil)
os.Exit(1)
}
ctx := context.Background()
err := a.LogControl.ResetLevels(ctx)
if err != nil {
a.Log.WithTags(spec.Tags{C: nil, L: "F", O: a, V: 1}, "%#v", maskAny(err))
}
}
示例10: ExecAnnadCmd
func (a *annad) ExecAnnadCmd(cmd *cobra.Command, args []string) {
a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnadCmd")
if len(args) > 0 {
cmd.HelpFunc()(cmd, nil)
os.Exit(1)
}
a.Log.WithTags(spec.Tags{C: nil, L: "I", O: a, V: 10}, "booting annad")
a.Log.WithTags(spec.Tags{C: nil, L: "I", O: a, V: 10}, "booting network")
go a.Network.Boot()
a.Log.WithTags(spec.Tags{C: nil, L: "I", O: a, V: 10}, "booting server")
go a.Server.Boot()
// Block the main goroutine forever. The process is only supposed to be ended
// by a call to Shutdown or ForceShutdown.
select {}
}
示例11: ExecAnnactlControlLogSetVerbosityCmd
func (a *annactl) ExecAnnactlControlLogSetVerbosityCmd(cmd *cobra.Command, args []string) {
a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnactlControlLogSetVerbosityCmd")
if len(args) != 1 {
cmd.HelpFunc()(cmd, nil)
os.Exit(1)
}
ctx := context.Background()
v, err := strconv.Atoi(args[0])
if err != nil {
a.Log.WithTags(spec.Tags{C: nil, L: "F", O: nil, V: 1}, "%#v", maskAny(err))
}
err = a.LogControl.SetVerbosity(ctx, v)
if err != nil {
a.Log.WithTags(spec.Tags{C: nil, L: "F", O: nil, V: 1}, "%#v", maskAny(err))
}
}
示例12: ExecAnnactlInterfaceTextReadFileCmd
func (a *annactl) ExecAnnactlInterfaceTextReadFileCmd(cmd *cobra.Command, args []string) {
a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnactlInterfaceTextReadFileCmd")
if len(args) == 0 || len(args) >= 2 {
cmd.HelpFunc()(cmd, nil)
os.Exit(1)
}
ctx := context.Background()
b, err := a.Service().FS().ReadFile(args[0])
if err != nil {
a.Log.WithTags(spec.Tags{C: nil, L: "F", O: a, V: 1}, "%#v", maskAny(err))
}
textRequest := textinput.MustNew()
err = json.Unmarshal(b, &textRequest)
if err != nil {
a.Log.WithTags(spec.Tags{C: nil, L: "F", O: a, V: 1}, "%#v", maskAny(err))
}
a.Service().TextInput().GetChannel() <- textRequest
go func() {
err = a.TextInterface.StreamText(ctx)
if err != nil {
a.Log.WithTags(spec.Tags{C: nil, L: "F", O: a, V: 1}, "%#v", maskAny(err))
}
}()
for {
select {
case textResponse := <-a.Service().TextOutput().GetChannel():
fmt.Printf("%s\n", textResponse.GetOutput())
}
}
}
示例13: runMissingCommand
func runMissingCommand(cmd *cobra.Command, args []string) {
stderr.Print("missing command")
cmd.HelpFunc()(cmd, args)
cmdExitCode = 2 // invalid argument
}
示例14: ExecAnnactlInterfaceTextReadCmd
func (a *annactl) ExecAnnactlInterfaceTextReadCmd(cmd *cobra.Command, args []string) {
a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnactlInterfaceTextReadCmd")
cmd.HelpFunc()(cmd, nil)
}
示例15: ShowHelp
// ShowHelp shows the command help.
func (cli *DockerCli) ShowHelp(cmd *cobra.Command, args []string) error {
cmd.SetOutput(cli.err)
cmd.HelpFunc()(cmd, args)
return nil
}