mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
// Copyright (C) 2022-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package configcmd
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/luxfi/cli/pkg/cobrautils"
|
|
"github.com/luxfi/cli/pkg/ux"
|
|
"github.com/luxfi/constants"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// lux config metrics command
|
|
func newMetricsCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "metrics [enable | disable]",
|
|
Short: "opt in or out of metrics collection",
|
|
Long: "set user metrics collection preferences",
|
|
RunE: handleMetricsSettings,
|
|
Args: cobrautils.ExactArgs(1),
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func handleMetricsSettings(_ *cobra.Command, args []string) error {
|
|
switch args[0] {
|
|
case constants.Enable:
|
|
ux.Logger.PrintToUser("Thank you for opting in Lux CLI usage metrics collection")
|
|
err := saveMetricsPreferences(true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
case constants.Disable:
|
|
ux.Logger.PrintToUser("Lux CLI usage metrics will no longer be collected")
|
|
err := saveMetricsPreferences(false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
default:
|
|
return errors.New("Invalid metrics argument '" + args[0] + "'")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func saveMetricsPreferences(enableMetrics bool) error {
|
|
return app.Conf.SetConfigValue(constants.ConfigMetricsEnabledKey, enableMetrics)
|
|
}
|