/
wrapper.go
53 lines (42 loc) · 1.59 KB
/
wrapper.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
package command
import (
"github.com/alecthomas/kingpin"
"github.com/echocat/kubor/common"
"github.com/echocat/kubor/wrapper"
)
func init() {
common.RegisterCliFactory(&Wrapper{})
}
type Wrapper struct {
Command
TargetDirectory string
Version string
}
func (instance *Wrapper) ConfigureCliCommands(context string, hc common.HasCommands, version string) error {
if context != "" {
return nil
}
wrapperCmd := hc.Command("wrapper", "Wrapper related commands.")
wrapperCmd.Flag("targetDirectory", "Directory where to install the wrapper to.").
Default(".").
StringVar(&instance.TargetDirectory)
wrapperCmd.Flag("version", "Version of the wrapper to be use.").
Default(version).
StringVar(&instance.Version)
wrapperCmd.Command("install", "Will install the wrapper - will fail if there is already a wrapper.").
Action(instance.executeInstall)
wrapperCmd.Command("update", "Will update an existing wrapper - will fail if there is not already a wrapper.").
Action(instance.executeUpdate)
wrapperCmd.Command("ensure", "Will ensure that a wrapper exist.").
Action(instance.executeEnsure)
return nil
}
func (instance *Wrapper) executeInstall(_ *kingpin.ParseContext) error {
return wrapper.Write(instance.TargetDirectory, instance.Version, wrapper.WoCreateOnly)
}
func (instance *Wrapper) executeUpdate(_ *kingpin.ParseContext) error {
return wrapper.Write(instance.TargetDirectory, instance.Version, wrapper.WoUpdateOnly)
}
func (instance *Wrapper) executeEnsure(_ *kingpin.ParseContext) error {
return wrapper.Write(instance.TargetDirectory, instance.Version, wrapper.WoCreateOrUpdate)
}