Adds a new command `gh auth setup-git [<hostname>]` that sets up git to use the GitHub CLI as a credential helper. The gist is that it runs these two git commands for each hostname the user is authenticated with. ``` git config --global --replace-all 'credential.https://github.com.helper' '' git config --global --add 'credential.https://github.com.helper' '!gh auth git-credential' ``` If a hostname flag is given, it'll setup GH CLI as a credential helper for only that hostname. If the user is not authenticated with any git hostnames, or the user is not authenticated with the hostname given as a flag, it'll print an error. Co-authored-by: Mislav Marohnić <mislav@github.com>
31 lines
1 KiB
Go
31 lines
1 KiB
Go
package auth
|
|
|
|
import (
|
|
gitCredentialCmd "github.com/cli/cli/v2/pkg/cmd/auth/gitcredential"
|
|
authLoginCmd "github.com/cli/cli/v2/pkg/cmd/auth/login"
|
|
authLogoutCmd "github.com/cli/cli/v2/pkg/cmd/auth/logout"
|
|
authRefreshCmd "github.com/cli/cli/v2/pkg/cmd/auth/refresh"
|
|
authSetupGitCmd "github.com/cli/cli/v2/pkg/cmd/auth/setupgit"
|
|
authStatusCmd "github.com/cli/cli/v2/pkg/cmd/auth/status"
|
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func NewCmdAuth(f *cmdutil.Factory) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "auth <command>",
|
|
Short: "Login, logout, and refresh your authentication",
|
|
Long: `Manage gh's authentication state.`,
|
|
}
|
|
|
|
cmdutil.DisableAuthCheck(cmd)
|
|
|
|
cmd.AddCommand(authLoginCmd.NewCmdLogin(f, nil))
|
|
cmd.AddCommand(authLogoutCmd.NewCmdLogout(f, nil))
|
|
cmd.AddCommand(authStatusCmd.NewCmdStatus(f, nil))
|
|
cmd.AddCommand(authRefreshCmd.NewCmdRefresh(f, nil))
|
|
cmd.AddCommand(gitCredentialCmd.NewCmdCredential(f, nil))
|
|
cmd.AddCommand(authSetupGitCmd.NewCmdSetupGit(f, nil))
|
|
|
|
return cmd
|
|
}
|