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

Function NewCmdStatus

pkg/cmd/auth/status/status.go:208–270  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*StatusOptions) error)

Source from the content-addressed store, hash-verified

206}
207
208func NewCmdStatus(f *cmdutil.Factory, runF func(*StatusOptions) error) *cobra.Command {
209 opts := &StatusOptions{
210 HttpClient: f.HttpClient,
211 IO: f.IOStreams,
212 Config: f.Config,
213 }
214
215 cmd := &cobra.Command{
216 Use: "status",
217 Args: cobra.ExactArgs(0),
218 Short: "Display active account and authentication state on each known GitHub host",
219 Long: heredoc.Docf(`
220 Display active account and authentication state on each known GitHub host.
221
222 For each host, the authentication state of each known account is tested and any issues are included in the output.
223 Each host section will indicate the active account, which will be used when targeting that host.
224
225 If an account on any host (or only the one given via %[1]s--hostname%[1]s) has authentication issues,
226 the command will exit with 1 and output to stderr. Note that when using the %[1]s--json%[1]s option, the command
227 will always exit with zero regardless of any authentication issues, unless there is a fatal error.
228
229 Any expired or near-expiry token that supports refreshing is refreshed automatically, unless %[1]s--no-refresh%[1]s is given.
230
231 To change the active account for a host, see %[1]sgh auth switch%[1]s.
232 `, "`"),
233 Example: heredoc.Doc(`
234 # Display authentication status for all accounts on all hosts
235 $ gh auth status
236
237 # Display authentication status for the active account on a specific host
238 $ gh auth status --active --hostname github.example.com
239
240 # Display tokens in plain text
241 $ gh auth status --show-token
242
243 # Format authentication status as JSON
244 $ gh auth status --json hosts
245
246 # Include plain text token in JSON output
247 $ gh auth status --json hosts --show-token
248
249 # Format hosts as a flat JSON array
250 $ gh auth status --json hosts --jq '.hosts | add'
251 `),
252 RunE: func(cmd *cobra.Command, args []string) error {
253 if runF != nil {
254 return runF(opts)
255 }
256
257 return statusRun(opts)
258 },
259 }
260
261 cmd.Flags().StringVarP(&opts.Hostname, "hostname", "h", "", "Check only a specific hostname's auth status")
262 cmd.Flags().BoolVarP(&opts.ShowToken, "show-token", "t", false, "Display the auth token")
263 cmd.Flags().BoolVarP(&opts.Active, "active", "a", false, "Display the active account only")
264 cmd.Flags().BoolVar(&opts.NoRefresh, "no-refresh", false, "Do not automatically refresh expired tokens")
265

Callers 1

Test_NewCmdStatusFunction · 0.70

Calls 2

statusRunFunction · 0.70

Tested by 1

Test_NewCmdStatusFunction · 0.56