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