-
Notifications
You must be signed in to change notification settings - Fork 167
/
telemetry.go
58 lines (46 loc) · 1.39 KB
/
telemetry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package cmd
import (
"context"
"github.com/azure/azure-dev/cli/azd/cmd/actions"
"github.com/azure/azure-dev/cli/azd/internal"
"github.com/azure/azure-dev/cli/azd/internal/telemetry"
"github.com/spf13/cobra"
)
const TelemetryCommandFlag = "telemetry"
const TelemetryUploadCommandFlag = "upload"
func telemetryActions(root *actions.ActionDescriptor) *actions.ActionDescriptor {
group := root.Add(TelemetryCommandFlag, &actions.ActionDescriptorOptions{
Command: &cobra.Command{
Short: "Manage telemetry",
Long: "Manage telemetry",
Hidden: true,
},
})
group.Add(TelemetryUploadCommandFlag, &actions.ActionDescriptorOptions{
Command: &cobra.Command{
Short: "Upload telemetry",
Long: "Upload telemetry",
Hidden: true,
},
ActionResolver: newUploadAction,
DisableTelemetry: true,
})
return group
}
type uploadAction struct {
rootOptions *internal.GlobalCommandOptions
}
func newUploadAction(global *internal.GlobalCommandOptions) actions.Action {
return &uploadAction{
rootOptions: global,
}
}
func (a *uploadAction) Run(ctx context.Context) (*actions.ActionResult, error) {
telemetrySystem := telemetry.GetTelemetrySystem()
if telemetrySystem == nil {
return nil, nil
}
return nil, telemetrySystem.RunBackgroundUpload(ctx, a.rootOptions.EnableDebugLogging)
}