refactor(internal/ooni): Context => Probe (#170)

Closes https://github.com/ooni/probe/issues/939
This commit is contained in:
Simone Basso 2020-11-13 19:01:06 +01:00 committed by GitHub
commit 9e238c27dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 90 additions and 90 deletions

View file

@ -137,12 +137,12 @@ func Onboarding(config *config.Config) error {
// MaybeOnboarding will run the onboarding process only if the informed consent
// config option is set to false
func MaybeOnboarding(c *ooni.Context) error {
if c.Config.InformedConsent == false {
if c.IsBatch == true {
func MaybeOnboarding(probe *ooni.Probe) error {
if probe.Config.InformedConsent == false {
if probe.IsBatch == true {
return errors.New("cannot run onboarding in batch mode")
}
if err := Onboarding(c.Config); err != nil {
if err := Onboarding(probe.Config); err != nil {
return errors.Wrap(err, "onboarding")
}
}
@ -155,26 +155,26 @@ func init() {
yes := cmd.Flag("yes", "Answer yes to all the onboarding questions.").Bool()
cmd.Action(func(_ *kingpin.ParseContext) error {
ctx, err := root.Init()
probe, err := root.Init()
if err != nil {
return err
}
if *yes == true {
ctx.Config.Lock()
ctx.Config.InformedConsent = true
ctx.Config.Unlock()
probe.Config.Lock()
probe.Config.InformedConsent = true
probe.Config.Unlock()
if err := ctx.Config.Write(); err != nil {
if err := probe.Config.Write(); err != nil {
log.WithError(err).Error("failed to write config file")
return err
}
return nil
}
if ctx.IsBatch == true {
if probe.IsBatch == true {
return errors.New("cannot do onboarding in batch mode")
}
return Onboarding(ctx.Config)
return Onboarding(probe.Config)
})
}