当前位置: 首页>>代码示例>>Golang>>正文


Golang Command.HelpFunc方法代码示例

本文整理汇总了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
}
开发者ID:kunalkushwaha,项目名称:octool,代码行数:30,代码来源:validate-state.go

示例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
}
开发者ID:kunalkushwaha,项目名称:octool,代码行数:30,代码来源:lint.go

示例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()
	}
}
开发者ID:brimstone,项目名称:go-pcd,代码行数:9,代码来源:hostname.go

示例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()
	}
}
开发者ID:brimstone,项目名称:go-pcd,代码行数:9,代码来源:docker_bip.go

示例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
}
开发者ID:nanopack,项目名称:portal,代码行数:12,代码来源:commands.go

示例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
}
开发者ID:nanopack,项目名称:logvac,代码行数:12,代码来源:main.go

示例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
}
开发者ID:nanopack,项目名称:pulse,代码行数:13,代码来源:main.go

示例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
}
开发者ID:nanopack,项目名称:hoarder,代码行数:15,代码来源:commands.go

示例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))
	}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:15,代码来源:annactl_control_log_reset_levels.go

示例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 {}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:20,代码来源:annad.go

示例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))
	}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:20,代码来源:annactl_control_log_set_verbosity.go

示例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())
		}
	}
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:37,代码来源:annactl_interface_text_read_file.go

示例13: runMissingCommand

func runMissingCommand(cmd *cobra.Command, args []string) {
	stderr.Print("missing command")
	cmd.HelpFunc()(cmd, args)
	cmdExitCode = 2 // invalid argument
}
开发者ID:nak3,项目名称:rkt,代码行数:5,代码来源:rkt.go

示例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)
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:5,代码来源:annactl_interface_text_read.go

示例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
}
开发者ID:harche,项目名称:docker,代码行数:6,代码来源:cli.go


注:本文中的github.com/spf13/cobra.Command.HelpFunc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。