storj/cmd/uplink/initial_setup.go
Erik van Velzen eab595397f cmd/uplink: add --analytics flag
Add a flag to enable/disable analytics so uplink can be run
non-interactively. Also when run non-interactively for the first time
it will not error any more but instead default to disable analytics.

Part of https://github.com/storj/storj/issues/5126

Change-Id: I07ac8a040664334efcb4e2536f26c330c1751a6f
2023-01-24 15:33:55 +00:00

47 lines
1.1 KiB
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"strings"
"github.com/zeebo/errs"
"storj.io/storj/cmd/uplink/ulext"
)
func saveInitialConfig(ctx context.Context, ex ulext.External, interactiveFlag bool, analyticsFlag *bool) error {
var analyticsEnabled bool
if analyticsFlag != nil {
analyticsEnabled = *analyticsFlag
} else {
if interactiveFlag {
answer, err := ex.PromptInput(ctx, `With your permission, Storj can `+
`automatically collect analytics information from your uplink CLI to `+
`help improve the quality and performance of our products. This `+
`information is sent only with your consent and is submitted `+
`anonymously to Storj Labs: (y/n)`)
if err != nil {
return errs.Wrap(err)
}
answer = strings.ToLower(answer)
analyticsEnabled = answer != "y" && answer != "yes"
} else {
analyticsEnabled = false
}
}
values := make(map[string]string)
if analyticsEnabled {
values["analytics.enabled"] = "true"
} else {
values["metrics.addr"] = ""
values["analytics.enabled"] = "false"
}
return ex.SaveConfig(values)
}