forked from bpicode/fritzctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest_export.go
37 lines (30 loc) · 1 KB
/
manifest_export.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
package cmd
import (
"os"
"github.com/bpicode/fritzctl/assert"
"github.com/bpicode/fritzctl/fritz"
"github.com/bpicode/fritzctl/manifest"
"github.com/mitchellh/cli"
)
type manifestExportCommand struct {
}
func (cmd *manifestExportCommand) Help() string {
return "Export the current state of the FRITZ!Box in manifest format and print it to stdout. Example usage: fritzctl --loglevel=error manifest export > current_state.yml"
}
func (cmd *manifestExportCommand) Synopsis() string {
return "export the current state of the FRITZ!Box in manifest format"
}
func (cmd *manifestExportCommand) Run(args []string) int {
c := clientLogin()
f := fritz.HomeAutomation(c)
l, err := f.ListDevices()
assert.NoError(err, "cannot obtain device data:", err)
plan := manifest.ConvertDevicelist(l)
manifest.ExporterTo(os.Stdout).Export(plan)
return 0
}
// ManifestExport is a factory creating commands for exporting manifest files.
func ManifestExport() (cli.Command, error) {
p := manifestExportCommand{}
return &p, nil
}