summaryrefslogtreecommitdiff
path: root/internal/clients/runclient.go
blob: 7a62fcc7306eb7daed2dd12f950989b0d7c77596 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package clients

import (
	"fmt"
	"runtime"

	"github.com/mimecast/dtail/internal/clients/handlers"
	"github.com/mimecast/dtail/internal/omode"
)

// RunClient is a client to run various commands on the server.
type RunClient struct {
	baseClient
}

// NewRunClient returns a new cat client.
func NewRunClient(args Args) (*RunClient, error) {
	args.Mode = omode.RunClient

	c := RunClient{
		baseClient: baseClient{
			Args:       args,
			throttleCh: make(chan struct{}, args.ConnectionsPerCPU*runtime.NumCPU()),
			retry:      false,
		},
	}

	c.init(c)
	return &c, nil
}

func (c RunClient) makeHandler(server string) handlers.Handler {
	return handlers.NewClientHandler(server)
}

func (c RunClient) makeCommands() (commands []string) {
	// Send "run COMMAND" to server!
	commands = append(commands, fmt.Sprintf("%s %s", c.Mode.String(), c.What))
	return
}