/
factory.go
69 lines (62 loc) · 2.1 KB
/
factory.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
57
58
59
60
61
62
63
64
65
66
67
68
69
package cli
import (
"os"
boshsys "github.com/cloudfoundry/bosh-utils/system"
"github.com/dpb587/ssoca/client"
clientcmd "github.com/dpb587/ssoca/client/cmd"
svc "github.com/dpb587/ssoca/service/env/client"
)
type Commands struct {
*clientcmd.ServiceCommand `no-flag:"true"`
Set Set `command:"set" description:"Configure the connection to an environment" alias:"add"`
Info Info `command:"info" description:"Show environment information"`
Services Services `command:"services" description:"Show current services available from the environment"`
List List `command:"list" description:"List all locally-configured environments"`
Rename Rename `command:"rename" description:"Set a new name for the environment"`
SetOption SetOption `command:"set-option" description:"Set a local client option in the environment"`
UpdateClient UpdateClient `command:"update-client" description:"Download the latest client from the environment"`
Unset Unset `command:"unset" description:"Remove all configuration for an environment" alias:"remove"`
}
// TODO convert to service factory rather than single env instance
func CreateCommands(runtime client.Runtime, cmdRunner boshsys.CmdRunner, fs boshsys.FileSystem, s *svc.Service) *Commands {
cmd := &clientcmd.ServiceCommand{
Runtime: runtime,
ServiceName: string(s.Type()),
}
return &Commands{
ServiceCommand: cmd,
Set: Set{
ServiceCommand: cmd,
FS: fs,
GetClient: s.GetClient,
},
Info: Info{
ServiceCommand: cmd,
GetClient: s.GetClient,
},
Services: Services{
ServiceCommand: cmd,
GetClient: s.GetClient,
},
List: List{
ServiceCommand: cmd,
},
Rename: Rename{
ServiceCommand: cmd,
},
SetOption: SetOption{
ServiceCommand: cmd,
},
UpdateClient: UpdateClient{
ServiceCommand: cmd,
SsocaExec: os.Args[0],
FS: fs,
CmdRunner: cmdRunner,
GetClient: s.GetClient,
GetDownloadClient: s.GetDownloadClient,
},
Unset: Unset{
ServiceCommand: cmd,
},
}
}