forked from bpicode/fritzctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest_apply.go
41 lines (34 loc) · 1.18 KB
/
manifest_apply.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
package cmd
import (
"github.com/bpicode/fritzctl/assert"
"github.com/bpicode/fritzctl/fritz"
"github.com/bpicode/fritzctl/manifest"
"github.com/mitchellh/cli"
)
type manifestApplyCommand struct {
}
func (cmd *manifestApplyCommand) Help() string {
return "Apply a given manifest against the state of the FRITZ!Box."
}
func (cmd *manifestApplyCommand) Synopsis() string {
return "apply a given manifest"
}
func (cmd *manifestApplyCommand) Run(args []string) int {
assert.StringSliceHasAtLeast(args, 1, "insufficient input: path to input manifest expected.")
target := parseManifest(args[0])
api := fritz.HomeAutomation(clientLogin())
src := cmd.obtainSourcePlan(api)
err := manifest.AhaAPIApplier(api).Apply(src, target)
assert.NoError(err, "application of manifest was not successful:", err)
return 0
}
// ManifestApply is a factory creating commands for applying manifest files.
func ManifestApply() (cli.Command, error) {
p := manifestApplyCommand{}
return &p, nil
}
func (cmd *manifestApplyCommand) obtainSourcePlan(api fritz.HomeAutomationAPI) *manifest.Plan {
l, err := api.ListDevices()
assert.NoError(err, "cannot obtain device data:", err)
return manifest.ConvertDevicelist(l)
}