MCPcopy
hub / github.com/cli/cli / Main

Function Main

internal/ghcmd/cmd.go:52–273  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50)
51
52func Main() exitCode {
53 buildDate := build.Date
54 buildVersion := build.Version
55 hasDebug, _ := utils.IsDebugEnabled()
56
57 cfg, cfgErr := config.NewConfig()
58 if cfgErr != nil {
59 fmt.Fprintf(os.Stderr, "warning: failed to load config: %s\n", cfgErr)
60 }
61 cfgFunc := func() (gh.Config, error) { return cfg, cfgErr }
62
63 var ioStreams *iostreams.IOStreams
64 if cfgErr == nil {
65 ioStreams = newIOStreams(cfg)
66 } else {
67 ioStreams = iostreams.System()
68 }
69 stderr := ioStreams.ErrOut
70
71 ghExecutablePath := executablePath("gh")
72
73 additionalCommonDimensions := ghtelemetry.Dimensions{
74 "version": strings.TrimPrefix(buildVersion, "v"),
75 "is_tty": strconv.FormatBool(ioStreams.IsStdoutTTY()),
76 "agent": string(agents.Detect()),
77 "ci": strconv.FormatBool(ci.IsCI()),
78 "github_actions": strconv.FormatBool(ci.IsGitHubActions()),
79 "accessible_colors": strconv.FormatBool(ioStreams.AccessibleColorsEnabled()),
80 "accessible_prompter": strconv.FormatBool(ioStreams.AccessiblePrompterEnabled()),
81 "color_labels": strconv.FormatBool(ioStreams.ColorLabels()),
82 "spinner_disabled": strconv.FormatBool(ioStreams.GetSpinnerDisabled()),
83 }
84
85 var telemetryService ghtelemetry.Service
86 switch {
87 case cfgErr != nil:
88 // Without a valid on-disk config we can't honour user telemetry preferences, so disable it to be safe.
89 telemetryService = &telemetry.NoOpService{}
90 default:
91 telemetryState := telemetry.ParseTelemetryState(cfg.Telemetry().Value)
92 telemetryDisabled := mightBeGHESUser(cfg)
93
94 switch telemetryState {
95 case telemetry.Disabled:
96 telemetryService = &telemetry.NoOpService{}
97 case telemetry.Logged:
98 // Always construct the real service in log mode so that the log
99 // flusher runs and surfaces an explicit "Telemetry payload: none"
100 // marker when no events will be sent. This gives the user an
101 // observable signal that telemetry is wired up even when their
102 // context (e.g. GHES) causes events to be dropped.
103 telemetryService = telemetry.NewService(
104 telemetry.LogFlusher(ioStreams.ErrOut, ioStreams.ColorEnabled()),
105 telemetry.WithAdditionalCommonDimensions(additionalCommonDimensions),
106 )
107 if telemetryDisabled {
108 telemetryService.Disable()
109 }

Callers 2

mainFunction · 0.92
ghMainFunction · 0.92

Calls 15

IsStdoutTTYMethod · 0.95
ColorLabelsMethod · 0.95
GetSpinnerDisabledMethod · 0.95
TelemetryMethod · 0.95
ColorEnabledMethod · 0.95
FlushMethod · 0.95
MigrateMethod · 0.95
ErrorMethod · 0.95
ScopesSuggestionMethod · 0.95
IsDebugEnabledFunction · 0.92

Tested by 1

ghMainFunction · 0.74