Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var BuildSubCommand = &cobra.Command{ Use: "build", Run: func(cmd *cobra.Command, args []string) { }, }
View Source
var Cmd = &cobra.Command{ Use: "hello", Short: "hello test", Args: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { return errors.New("requires at least one arg") } return fmt.Errorf("invalid color specified: %s", args[0]) }, Run: func(cmd *cobra.Command, args []string) { fmt.Println("Hello , World!") }, }
View Source
var GitCmd = &cobra.Command{ Use: "git", Short: "Git is distributed version control system", Long: `Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.`, Run: func(cmd *cobra.Command, args []string) { Error(cmd, args, errors.New("unrecognized command")) }, }
View Source
var PsCommand = &cobra.Command{ Use: "ps", Short: "这是一个操作ps的命令", Run: func(c *cobra.Command, args []string) { fmt.Println(" args is:", len(args)) fmt.Println("/bin/bash", "-c", "ps -ef| grep "+args[0]) if len(args) != 0 { cmd := exec.Command("/bin/bash", "-c", "ps -ef| grep "+args[0]) stdout, err := cmd.StdoutPipe() if err != nil { fmt.Printf("Error:can not obtain stdout pipe for command:%s\n", err) return } if err := cmd.Start(); err != nil { fmt.Println("Error:The command is err,", err) return } bytes, err := ioutil.ReadAll(stdout) if err != nil { fmt.Println("ReadAll Stdout:", err.Error()) return } if err := cmd.Wait(); err != nil { fmt.Println("wait:", err.Error()) return } fmt.Printf("stdout:\n\n %s", bytes) } }, }
View Source
var RootCommand = &cobra.Command{
Use: "cli",
Short: "cli is demo for cobra",
}
cobra 框架使用
Functions ¶
Types ¶
type MainConfig ¶
func LoadConfig ¶
func LoadConfig(path string) *MainConfig
Click to show internal directories.
Click to hide internal directories.