From d55cccc236cdbeadcadb71ae4657f005961ee08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Mon, 17 Sep 2018 16:16:56 +0200 Subject: [PATCH] Exit with non-zero code when trying to do interactive onboarding and --batch is set --- internal/cli/app/app.go | 3 ++- internal/cli/onboard/onboard.go | 5 +++++ internal/cli/root/root.go | 3 +++ ooni.go | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/cli/app/app.go b/internal/cli/app/app.go index c1b4cfb..0cb7a07 100644 --- a/internal/cli/app/app.go +++ b/internal/cli/app/app.go @@ -13,7 +13,8 @@ func Run() { root.Cmd.Version(ooni.Version) _, err := root.Cmd.Parse(os.Args[1:]) if err != nil { - log.WithError(err).Error("failed to parse arguments") + log.WithError(err).Error("failure in main command") + os.Exit(1) } return } diff --git a/internal/cli/onboard/onboard.go b/internal/cli/onboard/onboard.go index 108672a..ddbe97f 100644 --- a/internal/cli/onboard/onboard.go +++ b/internal/cli/onboard/onboard.go @@ -1,6 +1,8 @@ package onboard import ( + "errors" + "github.com/alecthomas/kingpin" "github.com/apex/log" "github.com/ooni/probe-cli/internal/cli/root" @@ -29,6 +31,9 @@ func init() { } return nil } + if ctx.IsBatch == true { + return errors.New("cannot do onboarding in batch mode") + } return onboard.Onboarding(ctx.Config) }) diff --git a/internal/cli/root/root.go b/internal/cli/root/root.go index c7749da..dd34dfb 100644 --- a/internal/cli/root/root.go +++ b/internal/cli/root/root.go @@ -48,6 +48,9 @@ func init() { if err != nil { return nil, err } + if *isBatch { + ctx.IsBatch = true + } return ctx, nil } diff --git a/ooni.go b/ooni.go index fdd740a..52d85bd 100644 --- a/ooni.go +++ b/ooni.go @@ -23,6 +23,7 @@ type Context struct { Config *config.Config DB sqlbuilder.Database Location *utils.LocationInfo + IsBatch bool Home string TempDir string @@ -60,6 +61,9 @@ func (c *Context) LocationLookup() error { // config option is set to false func (c *Context) MaybeOnboarding() error { if c.Config.InformedConsent == false { + if c.IsBatch == true { + return errors.New("cannot run onboarding in batch mode") + } if err := onboard.Onboarding(c.Config); err != nil { return errors.Wrap(err, "onboarding") }