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

Method String

pkg/cmd/auth/status/status.go:60–117  ·  view source on GitHub ↗
(cs *iostreams.ColorScheme)

Source from the content-addressed store, hash-verified

58}
59
60func (e authEntry) String(cs *iostreams.ColorScheme) string {
61 var sb strings.Builder
62
63 switch e.State {
64 case authEntryStateSuccess:
65 sb.WriteString(
66 fmt.Sprintf(" %s Logged in to %s account %s (%s)\n", cs.SuccessIcon(), e.Host, cs.Bold(e.Login), e.TokenSource),
67 )
68 activeStr := fmt.Sprintf("%v", e.Active)
69 sb.WriteString(fmt.Sprintf(" - Active account: %s\n", cs.Bold(activeStr)))
70 sb.WriteString(fmt.Sprintf(" - Git operations protocol: %s\n", cs.Bold(e.GitProtocol)))
71 sb.WriteString(fmt.Sprintf(" - Token: %s\n", cs.Bold(e.Token)))
72
73 if expectScopes(e.Token) {
74 sb.WriteString(fmt.Sprintf(" - Token scopes: %s\n", cs.Bold(displayScopes(e.Scopes))))
75 if err := shared.HeaderHasMinimumScopes(e.Scopes); err != nil {
76 if missingScopesError, ok := errors.AsType[*shared.MissingScopesError](err); ok {
77 missingScopes := strings.Join(missingScopesError.MissingScopes, ",")
78 sb.WriteString(fmt.Sprintf(" %s Missing required token scopes: %s\n",
79 cs.WarningIcon(),
80 cs.Bold(displayScopes(missingScopes))))
81 refreshInstructions := fmt.Sprintf("gh auth refresh -h %s", e.Host)
82 sb.WriteString(fmt.Sprintf(" - To request missing scopes, run: %s\n", cs.Bold(refreshInstructions)))
83 }
84 }
85 }
86
87 case authEntryStateError:
88 if e.Login != "" {
89 sb.WriteString(fmt.Sprintf(" %s Failed to log in to %s account %s (%s)\n", cs.Red("X"), e.Host, cs.Bold(e.Login), e.TokenSource))
90 } else {
91 sb.WriteString(fmt.Sprintf(" %s Failed to log in to %s using token (%s)\n", cs.Red("X"), e.Host, e.TokenSource))
92 }
93 activeStr := fmt.Sprintf("%v", e.Active)
94 sb.WriteString(fmt.Sprintf(" - Active account: %s\n", cs.Bold(activeStr)))
95 sb.WriteString(fmt.Sprintf(" - The token in %s is invalid.\n", e.TokenSource))
96 if authTokenWriteable(e.TokenSource) {
97 loginInstructions := fmt.Sprintf("gh auth login -h %s", e.Host)
98 if shared.AuthTokenRefreshable(e.Token, e.TokenSource) {
99 loginInstructions = fmt.Sprintf("gh auth refresh -h %s", e.Host)
100 }
101 logoutInstructions := fmt.Sprintf("gh auth logout -h %s -u %s", e.Host, e.Login)
102 sb.WriteString(fmt.Sprintf(" - To re-authenticate, run: %s\n", cs.Bold(loginInstructions)))
103 sb.WriteString(fmt.Sprintf(" - To forget about this account, run: %s\n", cs.Bold(logoutInstructions)))
104 }
105
106 case authEntryStateTimeout:
107 if e.Login != "" {
108 sb.WriteString(fmt.Sprintf(" %s Timeout trying to log in to %s account %s (%s)\n", cs.Red("X"), e.Host, cs.Bold(e.Login), e.TokenSource))
109 } else {
110 sb.WriteString(fmt.Sprintf(" %s Timeout trying to log in to %s using token (%s)\n", cs.Red("X"), e.Host, e.TokenSource))
111 }
112 activeStr := fmt.Sprintf("%v", e.Active)
113 sb.WriteString(fmt.Sprintf(" - Active account: %s\n", cs.Bold(activeStr)))
114 }
115
116 return sb.String()
117}

Callers

nothing calls this directly

Calls 11

HeaderHasMinimumScopesFunction · 0.92
AuthTokenRefreshableFunction · 0.92
expectScopesFunction · 0.85
displayScopesFunction · 0.85
authTokenWriteableFunction · 0.85
SuccessIconMethod · 0.80
BoldMethod · 0.80
JoinMethod · 0.80
WarningIconMethod · 0.80
RedMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected