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

Method String

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

Source from the content-addressed store, hash-verified

85}
86
87func (e authEntry) String(cs *iostreams.ColorScheme) string {
88 var sb strings.Builder
89
90 switch e.State {
91 case authEntryStateSuccess:
92 sb.WriteString(
93 fmt.Sprintf(" %s Logged in to %s account %s (%s)\n", cs.SuccessIcon(), e.Host, cs.Bold(e.Login), e.TokenSource),
94 )
95 activeStr := fmt.Sprintf("%v", e.Active)
96 sb.WriteString(fmt.Sprintf(" - Active account: %s\n", cs.Bold(activeStr)))
97 sb.WriteString(fmt.Sprintf(" - Git operations protocol: %s\n", cs.Bold(e.GitProtocol)))
98 sb.WriteString(fmt.Sprintf(" - Token: %s\n", cs.Bold(e.Token)))
99
100 if e.Refreshable {
101 e.writeExpiry(&sb, cs)
102 if e.justRefreshed {
103 sb.WriteString(" - Token refreshed just now\n")
104 }
105 }
106
107 if expectScopes(e.Token) {
108 sb.WriteString(fmt.Sprintf(" - Token scopes: %s\n", cs.Bold(displayScopes(e.Scopes))))
109 if err := shared.HeaderHasMinimumScopes(e.Scopes); err != nil {
110 if missingScopesError, ok := errors.AsType[*shared.MissingScopesError](err); ok {
111 missingScopes := strings.Join(missingScopesError.MissingScopes, ",")
112 sb.WriteString(fmt.Sprintf(" %s Missing required token scopes: %s\n",
113 cs.WarningIcon(),
114 cs.Bold(displayScopes(missingScopes))))
115 refreshInstructions := fmt.Sprintf("gh auth refresh -h %s", e.Host)
116 sb.WriteString(fmt.Sprintf(" - To request missing scopes, run: %s\n", cs.Bold(refreshInstructions)))
117 }
118 }
119 }
120
121 case authEntryStateError:
122 if e.expiredWithoutRefresh {
123 sb.WriteString(fmt.Sprintf(" %s Token for %s account %s (%s) has expired\n", cs.Red("X"), e.Host, cs.Bold(e.Login), e.TokenSource))
124 activeStr := fmt.Sprintf("%v", e.Active)
125 sb.WriteString(fmt.Sprintf(" - Active account: %s\n", cs.Bold(activeStr)))
126 e.writeExpiry(&sb, cs)
127 if e.RefreshTokenExpiresAt != nil && !e.RefreshTokenExpiresAt.After(timeNow()) {
128 loginInstructions := fmt.Sprintf("gh auth login -h %s", e.Host)
129 sb.WriteString(fmt.Sprintf(" - To re-authenticate, run: %s\n", cs.Bold(loginInstructions)))
130 } else {
131 sb.WriteString(fmt.Sprintf(" - To refresh it, run %s (without %s)\n", cs.Bold("gh auth status"), cs.Bold("--no-refresh")))
132 }
133 break
134 }
135 if e.Login != "" {
136 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))
137 } else {
138 sb.WriteString(fmt.Sprintf(" %s Failed to log in to %s using token (%s)\n", cs.Red("X"), e.Host, e.TokenSource))
139 }
140 activeStr := fmt.Sprintf("%v", e.Active)
141 sb.WriteString(fmt.Sprintf(" - Active account: %s\n", cs.Bold(activeStr)))
142 sb.WriteString(fmt.Sprintf(" - The token in %s is invalid.\n", e.TokenSource))
143 if authTokenWriteable(e.TokenSource) {
144 loginInstructions := fmt.Sprintf("gh auth login -h %s", e.Host)

Callers

nothing calls this directly

Calls 12

writeExpiryMethod · 0.95
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