2018-09-17 16:33:56 +02:00
|
|
|
package reset
|
2018-09-10 15:15:29 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/alecthomas/kingpin"
|
|
|
|
"github.com/apex/log"
|
|
|
|
"github.com/ooni/probe-cli/internal/cli/root"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cmd := root.Command("reset", "Cleanup an old or experimental installation")
|
|
|
|
force := cmd.Flag("force", "Force deleting the OONI Home").Bool()
|
|
|
|
|
|
|
|
cmd.Action(func(_ *kingpin.ParseContext) error {
|
|
|
|
ctx, err := root.Init()
|
|
|
|
if err != nil {
|
2018-09-26 15:09:59 +02:00
|
|
|
log.WithError(err).Error("failed to init root context")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// We need to first the DB otherwise the DB will be rewritten on close when
|
|
|
|
// we delete the home directory.
|
2020-11-13 20:07:30 +01:00
|
|
|
err = ctx.DB().Close()
|
2018-09-26 15:09:59 +02:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("failed to close the DB")
|
2018-09-10 15:15:29 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if *force == true {
|
2020-11-13 20:07:30 +01:00
|
|
|
os.RemoveAll(ctx.Home())
|
|
|
|
log.Infof("Deleted %s", ctx.Home())
|
2018-09-10 15:15:29 +02:00
|
|
|
} else {
|
2020-11-13 20:07:30 +01:00
|
|
|
log.Infof("Run with --force to delete %s", ctx.Home())
|
2018-09-10 15:15:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|