-
Notifications
You must be signed in to change notification settings - Fork 10
/
view.go
56 lines (48 loc) · 1.61 KB
/
view.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package view
import (
"fmt"
"github.com/MakeNowJust/heredoc/v2"
"github.com/OctopusDeploy/cli/pkg/cmd"
listeningTentacle "github.com/OctopusDeploy/cli/pkg/cmd/worker/listening-tentacle/view"
pollingTentacle "github.com/OctopusDeploy/cli/pkg/cmd/worker/polling-tentacle/view"
"github.com/OctopusDeploy/cli/pkg/cmd/worker/shared"
ssh "github.com/OctopusDeploy/cli/pkg/cmd/worker/ssh/view"
"github.com/OctopusDeploy/cli/pkg/constants"
"github.com/OctopusDeploy/cli/pkg/factory"
"github.com/OctopusDeploy/cli/pkg/machinescommon"
"github.com/OctopusDeploy/cli/pkg/usage"
"github.com/spf13/cobra"
)
func NewCmdView(f factory.Factory) *cobra.Command {
flags := shared.NewViewFlags()
cmd := &cobra.Command{
Args: usage.ExactArgs(1),
Use: "view {<name> | <id>}",
Short: "View a worker",
Long: "View a worker in Octopus Deploy",
Example: heredoc.Docf(`
$ %[1]s worker view Machines-100
$ %[1]s worker view 'worker'
`, constants.ExecutableName),
RunE: func(c *cobra.Command, args []string) error {
return ViewRun(shared.NewViewOptions(flags, cmd.NewDependencies(f, c), args))
},
}
machinescommon.RegisterWebFlag(cmd, flags.WebFlags)
return cmd
}
func ViewRun(opts *shared.ViewOptions) error {
var worker, err = opts.Client.Workers.GetByIdentifier(opts.IdOrName)
if err != nil {
return err
}
switch worker.Endpoint.GetCommunicationStyle() {
case "TentaclePassive":
return listeningTentacle.ViewRun(opts)
case "TentacleActive":
return pollingTentacle.ViewRun(opts)
case "Ssh":
return ssh.ViewRun(opts)
}
return fmt.Errorf("unsupported worker '%s'", worker.Endpoint.GetCommunicationStyle())
}