From 5055eaa88ad62feadab09a823dd46e4042228eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Mon, 10 Sep 2018 15:15:29 +0200 Subject: [PATCH] Add info and reset commands --- cmd/ooni/main.go | 1 + internal/cli/info/info.go | 14 ++++++++++++-- internal/cli/reset/reset.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 internal/cli/reset/reset.go diff --git a/cmd/ooni/main.go b/cmd/ooni/main.go index 2b56450..748fb31 100644 --- a/cmd/ooni/main.go +++ b/cmd/ooni/main.go @@ -9,6 +9,7 @@ import ( _ "github.com/ooni/probe-cli/internal/cli/list" _ "github.com/ooni/probe-cli/internal/cli/nettest" _ "github.com/ooni/probe-cli/internal/cli/onboard" + _ "github.com/ooni/probe-cli/internal/cli/reset" _ "github.com/ooni/probe-cli/internal/cli/run" _ "github.com/ooni/probe-cli/internal/cli/show" _ "github.com/ooni/probe-cli/internal/cli/upload" diff --git a/internal/cli/info/info.go b/internal/cli/info/info.go index 5743dff..13f4834 100644 --- a/internal/cli/info/info.go +++ b/internal/cli/info/info.go @@ -10,8 +10,18 @@ func init() { cmd := root.Command("info", "Display information about OONI Probe") cmd.Action(func(_ *kingpin.ParseContext) error { - log.Info("Info") - log.Error("this function is not implemented") + ctx, err := root.Init() + if err != nil { + log.Errorf("%s", err) + return err + } + log.WithFields(log.Fields{ + "path": ctx.Home, + }).Info("Home") + log.WithFields(log.Fields{ + "path": ctx.TempDir, + }).Info("TempDir") + return nil }) } diff --git a/internal/cli/reset/reset.go b/internal/cli/reset/reset.go new file mode 100644 index 0000000..9a07ed8 --- /dev/null +++ b/internal/cli/reset/reset.go @@ -0,0 +1,30 @@ +package clean + +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 { + log.Errorf("%s", err) + return err + } + if *force == true { + os.RemoveAll(ctx.Home) + log.Infof("Deleted %s", ctx.Home) + } else { + log.Infof("Run with --force to delete %s", ctx.Home) + } + + return nil + }) +}