Exit with non-zero code when trying to do interactive onboarding and --batch is set
This commit is contained in:
parent
6c49bd694f
commit
d55cccc236
|
@ -13,7 +13,8 @@ func Run() {
|
||||||
root.Cmd.Version(ooni.Version)
|
root.Cmd.Version(ooni.Version)
|
||||||
_, err := root.Cmd.Parse(os.Args[1:])
|
_, err := root.Cmd.Parse(os.Args[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("failed to parse arguments")
|
log.WithError(err).Error("failure in main command")
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package onboard
|
package onboard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin"
|
"github.com/alecthomas/kingpin"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/ooni/probe-cli/internal/cli/root"
|
"github.com/ooni/probe-cli/internal/cli/root"
|
||||||
|
@ -29,6 +31,9 @@ func init() {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if ctx.IsBatch == true {
|
||||||
|
return errors.New("cannot do onboarding in batch mode")
|
||||||
|
}
|
||||||
|
|
||||||
return onboard.Onboarding(ctx.Config)
|
return onboard.Onboarding(ctx.Config)
|
||||||
})
|
})
|
||||||
|
|
|
@ -48,6 +48,9 @@ func init() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if *isBatch {
|
||||||
|
ctx.IsBatch = true
|
||||||
|
}
|
||||||
|
|
||||||
return ctx, nil
|
return ctx, nil
|
||||||
}
|
}
|
||||||
|
|
4
ooni.go
4
ooni.go
|
@ -23,6 +23,7 @@ type Context struct {
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
DB sqlbuilder.Database
|
DB sqlbuilder.Database
|
||||||
Location *utils.LocationInfo
|
Location *utils.LocationInfo
|
||||||
|
IsBatch bool
|
||||||
|
|
||||||
Home string
|
Home string
|
||||||
TempDir string
|
TempDir string
|
||||||
|
@ -60,6 +61,9 @@ func (c *Context) LocationLookup() error {
|
||||||
// config option is set to false
|
// config option is set to false
|
||||||
func (c *Context) MaybeOnboarding() error {
|
func (c *Context) MaybeOnboarding() error {
|
||||||
if c.Config.InformedConsent == false {
|
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 {
|
if err := onboard.Onboarding(c.Config); err != nil {
|
||||||
return errors.Wrap(err, "onboarding")
|
return errors.Wrap(err, "onboarding")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user