-
Notifications
You must be signed in to change notification settings - Fork 8
/
restore.go
44 lines (37 loc) · 878 Bytes
/
restore.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
package cmd
import (
"path/filepath"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
func Restore() *cli.Command {
return &cli.Command{
Name: "restore",
Usage: "Restore hosts file from backup",
Action: restore,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "input",
Aliases: []string{"i"},
Usage: "File location to restore a backup from, default <hostsdir>/.hosts",
},
},
}
}
func restore(c *cli.Context) error {
hf, err := loadHostsfile(c, false)
if err != nil {
// debug only, no problem if file doesn't exist we just need path
logrus.Debugf("destination hosts file not found: %s", hf.Path)
}
input := c.String("input")
if input == "" {
input = filepath.Join(
filepath.Dir(hf.Path),
"."+filepath.Base(hf.Path))
}
if err := copyFile(input, hf.Path); err != nil {
return err
}
return debugFooter(c)
}