@@ -109,7 +109,8 @@ var configByHost = map[string]oauth2.Config{
109109var (
110110 verbose bool
111111 // populated by GoReleaser https://goreleaser.com/cookbooks/using-main.version
112- version = "dev"
112+ version = "dev"
113+ qrencodeType string
113114)
114115
115116func getVersion () string {
@@ -149,6 +150,7 @@ func main() {
149150 flag .BoolVar (& verbose , "verbose" , false , "log debug information to stderr" )
150151 var device bool
151152 flag .BoolVar (& device , "device" , false , "instead of opening a web browser locally, print a code to enter on another device" )
153+ flag .StringVar (& qrencodeType , "qr" , "" , "qrencode type" )
152154 flag .Usage = func () {
153155 printVersion ()
154156 fmt .Fprintln (os .Stderr , "usage: git credential-oauth [<options>] <action>" )
@@ -475,6 +477,19 @@ func getDeviceToken(ctx context.Context, c oauth2.Config) (*oauth2.Token, error)
475477 if verbose {
476478 fmt .Fprintf (os .Stderr , "%+v\n " , deviceAuth )
477479 }
480+ if deviceAuth .VerificationURIComplete != "" && qrencodeType != "" {
481+ qrencodePath , err := exec .LookPath ("qrencode" )
482+ if err == nil {
483+ cmd := exec .Command (qrencodePath , "-t" , qrencodeType , deviceAuth .VerificationURIComplete )
484+ bytes , err := cmd .CombinedOutput ()
485+ if err != nil {
486+ log .Fatalln (err )
487+ }
488+ if err == nil {
489+ fmt .Fprintf (os .Stderr , "%s\n " , bytes )
490+ }
491+ }
492+ }
478493 fmt .Fprintf (os .Stderr , "Please enter code %s at %s\n " , deviceAuth .UserCode , deviceAuth .VerificationURI )
479494 return c .DeviceAccessToken (ctx , deviceAuth )
480495}
0 commit comments