MCPcopy
hub / github.com/cli/cli / NewCmdStatus

Function NewCmdStatus

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

Source from the content-addressed store, hash-verified

129}
130
131func NewCmdStatus(f *cmdutil.Factory, runF func(*StatusOptions) error) *cobra.Command {
132 opts := &StatusOptions{
133 HttpClient: f.HttpClient,
134 IO: f.IOStreams,
135 Config: f.Config,
136 }
137
138 cmd := &cobra.Command{
139 Use: "status",
140 Args: cobra.ExactArgs(0),
141 Short: "Display active account and authentication state on each known GitHub host",
142 Long: heredoc.Docf(`
143 Display active account and authentication state on each known GitHub host.
144
145 For each host, the authentication state of each known account is tested and any issues are included in the output.
146 Each host section will indicate the active account, which will be used when targeting that host.
147
148 If an account on any host (or only the one given via %[1]s--hostname%[1]s) has authentication issues,
149 the command will exit with 1 and output to stderr. Note that when using the %[1]s--json%[1]s option, the command
150 will always exit with zero regardless of any authentication issues, unless there is a fatal error.
151
152 To change the active account for a host, see %[1]sgh auth switch%[1]s.
153 `, "`"),
154 Example: heredoc.Doc(`
155 # Display authentication status for all accounts on all hosts
156 $ gh auth status
157
158 # Display authentication status for the active account on a specific host
159 $ gh auth status --active --hostname github.example.com
160
161 # Display tokens in plain text
162 $ gh auth status --show-token
163
164 # Format authentication status as JSON
165 $ gh auth status --json hosts
166
167 # Include plain text token in JSON output
168 $ gh auth status --json hosts --show-token
169
170 # Format hosts as a flat JSON array
171 $ gh auth status --json hosts --jq '.hosts | add'
172 `),
173 RunE: func(cmd *cobra.Command, args []string) error {
174 if runF != nil {
175 return runF(opts)
176 }
177
178 return statusRun(opts)
179 },
180 }
181
182 cmd.Flags().StringVarP(&opts.Hostname, "hostname", "h", "", "Check only a specific hostname's auth status")
183 cmd.Flags().BoolVarP(&opts.ShowToken, "show-token", "t", false, "Display the auth token")
184 cmd.Flags().BoolVarP(&opts.Active, "active", "a", false, "Display the active account only")
185
186 // the json flags are intentionally not given a shorthand to avoid conflict with -t/--show-token
187 cmdutil.AddJSONFlagsWithoutShorthand(cmd, &opts.Exporter, authStatusFields)
188

Callers 1

Test_NewCmdStatusFunction · 0.70

Calls 2

statusRunFunction · 0.70

Tested by 1

Test_NewCmdStatusFunction · 0.56