Golang Command.HelpFunc Examples

Golang Command.HelpFunc - 18 examples found. These are the top rated real world Golang examples of github.com/spf13/cobra.Command.HelpFunc extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
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
}
Example #2
0
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
}
Example #3
0
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()
	}
}
Example #4
0
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()
	}
}
Example #5
0
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
}
Example #6
0
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
}