| 43 | } |
| 44 | |
| 45 | func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Command { |
| 46 | opts := &LoginOptions{ |
| 47 | IO: f.IOStreams, |
| 48 | Config: f.Config, |
| 49 | HttpClient: f.HttpClient, |
| 50 | PlainHttpClient: f.PlainHttpClient, |
| 51 | GitClient: f.GitClient, |
| 52 | Prompter: f.Prompter, |
| 53 | Browser: f.Browser, |
| 54 | } |
| 55 | |
| 56 | var tokenStdin bool |
| 57 | |
| 58 | cmd := &cobra.Command{ |
| 59 | Use: "login", |
| 60 | Args: cobra.ExactArgs(0), |
| 61 | Short: "Log in to a GitHub account", |
| 62 | Long: heredoc.Docf(` |
| 63 | Authenticate with a GitHub host. |
| 64 | |
| 65 | The default hostname is %[1]sgithub.com%[1]s. This can be overridden using the %[1]s--hostname%[1]s |
| 66 | flag. |
| 67 | |
| 68 | The default authentication mode is a web-based browser flow. After completion, an |
| 69 | authentication token will be stored securely in the system credential store. |
| 70 | If a credential store is not found or there is an issue using it gh will fallback |
| 71 | to writing the token to a plain text file. See %[1]sgh auth status%[1]s for its |
| 72 | stored location. |
| 73 | |
| 74 | Alternatively, use %[1]s--with-token%[1]s to pass in a personal access token (classic) on standard input. |
| 75 | The minimum required scopes for the token are: %[1]srepo%[1]s, %[1]sread:org%[1]s, and %[1]sgist%[1]s. |
| 76 | Take care when passing a fine-grained personal access token to %[1]s--with-token%[1]s |
| 77 | as the inherent scoping to certain resources may cause confusing behaviour when interacting with other |
| 78 | resources. Favour setting %[1]sGH_TOKEN%[1]s for fine-grained personal access token usage. |
| 79 | |
| 80 | Alternatively, gh will use the authentication token found in environment variables. |
| 81 | This method is most suitable for "headless" use of gh such as in automation. See |
| 82 | %[1]sgh help environment%[1]s for more info. |
| 83 | |
| 84 | To use gh in GitHub Actions, add %[1]sGH_TOKEN: ${{ github.token }}%[1]s to %[1]senv%[1]s. |
| 85 | |
| 86 | The git protocol to use for git operations on this host can be set with %[1]s--git-protocol%[1]s, |
| 87 | or during the interactive prompting. Although login is for a single account on a host, setting |
| 88 | the git protocol will take effect for all users on the host. |
| 89 | |
| 90 | Specifying %[1]sssh%[1]s for the git protocol will detect existing SSH keys to upload, |
| 91 | prompting to create and upload a new key if one is not found. This can be skipped with |
| 92 | %[1]s--skip-ssh-key%[1]s flag. |
| 93 | |
| 94 | For more information on OAuth scopes, see |
| 95 | <https://docs.github.com/en/developers/apps/building-oauth-apps/scopes-for-oauth-apps/>. |
| 96 | `, "`"), |
| 97 | Example: heredoc.Doc(` |
| 98 | # Start interactive setup |
| 99 | $ gh auth login |
| 100 | |
| 101 | # Open a browser to authenticate and copy one-time OAuth code to clipboard |
| 102 | $ gh auth login --web --clipboard |