MCPcopy Create free account
hub / github.com/cli/cli / Main

Function Main

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

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
ColorSchemeMethod · 0.95
ScopesSuggestionMethod · 0.95

Tested by 1

ghMainFunction · 0.74