cmd

package
v0.0.0-...-c9ef0eb Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cmd /*

Package cmd /*

Index

Constants

This section is empty.

Variables

View Source
var ServerCmd = &cobra.Command{
	Use:   "server",
	Short: "command server",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println(os.Args)
		go etcdmain.Main(checkArgs(os.Args))

		cli, err := clientv3.New(clientv3.Config{
			Endpoints: []string{"127.0.0.1:2379"},
		})
		if err != nil {
			log.Fatal(err)
		}
		defer cli.Close()
		kvc := clientv3.NewKV(cli)
		response, err := kvc.Put(context.Background(), "key", "value")
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(response)

		value, err := kvc.Get(context.Background(), "key")
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(value)
	},
}

ServerCmd represents the server command

View Source
var ShellCmd = &cobra.Command{
	Use:   "shell",
	Short: "run shell command on remote hosts",
	Run: func(cmd *cobra.Command, args []string) {
		content, err := os.ReadFile(cfgFile)
		if err != nil {
			panic(err)
		}
		err = yaml.Unmarshal(content, &server)
		if err != nil {
			panic(err)
		}
		var errs []error

		for _, host := range server.Hosts {
			c, err := connector.NewConnection(connector.Config{
				Username: host.User,
				Password: host.Password,
				Address:  host.Address,
			})
			if err != nil {
				errs = append(errs, err)
			}
			if command != "" {
				server.Do = command
			}
			output, code, err := c.Exec(host, server.Do)
			if err != nil {
				errs = append(errs, err)
			}
			fmt.Println(output)
			fmt.Println(code)
		}
	},
}

ShellCmd represents the shell command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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