src

package
v0.0.0-...-0566735 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

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

func Error

func Error(cmd *cobra.Command, args []string, err error)

func Execute

func Execute()

func HiGreet

func HiGreet()

urfave 框架使用

func Str

func Str(st string) string

读取配置文件

Types

type MainConfig

type MainConfig struct {
	Port    string
	Address string
}

func LoadConfig

func LoadConfig(path string) *MainConfig

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL