diff --git a/go.mod b/go.mod index e9c6cd2..c98a88d 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,9 @@ module github.com/cli/go-gh/v2 go 1.21 require ( + github.com/AlecAivazis/survey/v2 v2.3.7 github.com/MakeNowJust/heredoc v1.0.0 - github.com/charmbracelet/glamour v0.5.1-0.20220727184942-e70ff2d969da + github.com/charmbracelet/glamour v0.6.0 github.com/cli/browser v1.1.0 github.com/cli/safeexec v1.0.0 github.com/cli/shurcooL-graphql v0.0.3 @@ -13,7 +14,7 @@ require ( github.com/itchyny/gojq v0.12.13 github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d github.com/muesli/reflow v0.3.0 - github.com/muesli/termenv v0.12.0 + github.com/muesli/termenv v0.13.0 github.com/stretchr/testify v1.7.0 github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e golang.org/x/sys v0.8.0 @@ -25,22 +26,24 @@ require ( require ( github.com/alecthomas/chroma v0.10.0 // indirect + github.com/aymanbagabas/go-osc52 v1.0.3 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2 v1.4.0 // indirect github.com/gorilla/css v1.0.0 // indirect github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect github.com/itchyny/timefmt-go v0.1.5 // indirect + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/kr/pretty v0.1.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect - github.com/microcosm-cc/bluemonday v1.0.20 // indirect + github.com/microcosm-cc/bluemonday v1.0.21 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.4 // indirect - github.com/yuin/goldmark v1.4.4 // indirect + github.com/yuin/goldmark v1.5.2 // indirect github.com/yuin/goldmark-emoji v1.0.1 // indirect golang.org/x/net v0.7.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect diff --git a/go.sum b/go.sum index a3044a7..37693f1 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,25 @@ +github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ= +github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo= github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ= github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= +github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= +github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek= github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s= +github.com/aymanbagabas/go-osc52 v1.0.3 h1:DTwqENW7X9arYimJrPeGZcV0ln14sGMt3pHZspWD+Mg= +github.com/aymanbagabas/go-osc52 v1.0.3/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= -github.com/charmbracelet/glamour v0.5.1-0.20220727184942-e70ff2d969da h1:FGz53GWQRiKQ/5xUsoCCkewSQIC7u81Scaxx2nUy3nM= -github.com/charmbracelet/glamour v0.5.1-0.20220727184942-e70ff2d969da/go.mod h1:HXz79SMFnF9arKxqeoHWxmo1BhplAH7wehlRhKQIL94= +github.com/charmbracelet/glamour v0.6.0 h1:wi8fse3Y7nfcabbbDuwolqTqMQPMnVPeZhDM273bISc= +github.com/charmbracelet/glamour v0.6.0/go.mod h1:taqWV4swIMMbWALc0m7AfE9JkPSU8om2538k9ITBxOc= github.com/cli/browser v1.1.0 h1:xOZBfkfY9L9vMBgqb1YwRirGu6QFaQ5dP/vXt5ENSOY= github.com/cli/browser v1.1.0/go.mod h1:HKMQAt9t12kov91Mn7RfZxyJQQgWgyS/3SZswlZ5iTI= github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI= github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q= github.com/cli/shurcooL-graphql v0.0.3 h1:CtpPxyGDs136/+ZeyAfUKYmcQBjDlq5aqnrDCW5Ghh8= github.com/cli/shurcooL-graphql v0.0.3/go.mod h1:tlrLmw/n5Q/+4qSvosT+9/W5zc8ZMjnJeYBxSdb4nWA= +github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI= +github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -25,10 +33,14 @@ github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslC github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/henvic/httpretty v0.0.6 h1:JdzGzKZBajBfnvlMALXXMVQWxWMF/ofTy8C3/OSUTxs= github.com/henvic/httpretty v0.0.6/go.mod h1:X38wLjWXHkXT7r2+uK8LjCMne9rsuNaBLJ+5cU2/Pmo= +github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog= +github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= github.com/itchyny/gojq v0.12.13 h1:IxyYlHYIlspQHHTE0f3cJF0NKDMfajxViuhBLnHd/QU= github.com/itchyny/gojq v0.12.13/go.mod h1:JzwzAqenfhrPUuwbmEz3nu3JQmFLlQTQMUcOdnu/Sf4= github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE= github.com/itchyny/timefmt-go v0.1.5/go.mod h1:nEP7L+2YmAbT2kZ2HfSs1d8Xtw9LY8D2stDBckWakZ8= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -36,27 +48,26 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= -github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= -github.com/microcosm-cc/bluemonday v1.0.19/go.mod h1:QNzV2UbLK2/53oIIwTOyLUSABMkjZ4tqiyC1g/DyqxE= -github.com/microcosm-cc/bluemonday v1.0.20 h1:flpzsq4KU3QIYAYGV/szUat7H+GPOXR0B2JU5A1Wp8Y= -github.com/microcosm-cc/bluemonday v1.0.20/go.mod h1:yfBmMi8mxvaZut3Yytv+jTXRY8mxyjJ0/kQBTElld50= +github.com/microcosm-cc/bluemonday v1.0.21 h1:dNH3e4PSyE4vNX+KlRGHT5KrSvjeUkoNPwEORjffHJg= +github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= -github.com/muesli/termenv v0.11.0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= -github.com/muesli/termenv v0.12.0 h1:KuQRUE3PgxRFWhq4gHvZtPSLCGDqM5q/cYr1pZ39ytc= -github.com/muesli/termenv v0.12.0/go.mod h1:WCCv32tusQ/EEZ5S8oUIIrC/nIuBcxCVqlN4Xfkv+7A= +github.com/muesli/termenv v0.13.0 h1:wK20DRpJdDX8b7Ek2QfhvqhRQFZ237RGRO0RQ/Iqdy0= +github.com/muesli/termenv v0.13.0/go.mod h1:sP1+uffeLaEYpyOTb8pLCUctGcGLnoFjSn4YJK5e2bc= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= @@ -68,26 +79,37 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e h1:BuzhfgfWQbX0dWzYzT1zsORLnHRv3bcRcsaUk0VmXA8= github.com/thlib/go-timezone-local v0.0.0-20210907160436-ef149e42d28e/go.mod h1:/Tnicc6m/lsJE0irFMA0LfIwTBo4QP7A8IfyIv4zZKI= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.4.4 h1:zNWRjYUW32G9KirMXYHQHVNFkXvMI7LpgNW2AgYAoIs= -github.com/yuin/goldmark v1.4.4/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yuin/goldmark v1.5.2 h1:ALmeCk/px5FSm1MAcFBAsVKZjDuMVj8Tm7FFIlMJnqU= +github.com/yuin/goldmark v1.5.2/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark-emoji v1.0.1 h1:ctuWEyzGBwiucEqxzwe0SOYDXPAucOrE9NQC18Wa1os= github.com/yuin/goldmark-emoji v1.0.1/go.mod h1:2w1E6FEWLcDQkoTE+7HU6QF1F6SLlNGjRIBbIZQFqkQ= -golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= +golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -97,11 +119,16 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pkg/prompter/mock.go b/pkg/prompter/mock.go new file mode 100644 index 0000000..0a47193 --- /dev/null +++ b/pkg/prompter/mock.go @@ -0,0 +1,182 @@ +package prompter + +import ( + "fmt" + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func NewPrompterMock(t *testing.T) *PrompterMock { + m := &PrompterMock{ + t: t, + selectStubs: []selectStub{}, + multiSelectStubs: []multiSelectStub{}, + inputStubs: []inputStub{}, + passwordStubs: []passwordStub{}, + confirmStubs: []confirmStub{}, + } + t.Cleanup(m.verify) + return m +} + +type PrompterMock struct { + t *testing.T + selectStubs []selectStub + multiSelectStubs []multiSelectStub + inputStubs []inputStub + passwordStubs []passwordStub + confirmStubs []confirmStub +} + +type selectStub struct { + prompt string + expectedOptions []string + fn func(string, string, []string) (int, error) +} + +type multiSelectStub struct { + prompt string + expectedOptions []string + fn func(string, []string, []string) ([]int, error) +} + +type inputStub struct { + prompt string + fn func(string, string) (string, error) +} + +type passwordStub struct { + prompt string + fn func(string) (string, error) +} + +type confirmStub struct { + Prompt string + Fn func(string, bool) (bool, error) +} + +func (m *PrompterMock) Select(prompt, defaultValue string, options []string) (int, error) { + var s selectStub + if len(m.selectStubs) == 0 { + return -1, noSuchPromptErr(prompt) + } + s = m.selectStubs[0] + m.selectStubs = m.selectStubs[1:len(m.selectStubs)] + if s.prompt != prompt { + return -1, noSuchPromptErr(prompt) + } + assertOptions(m.t, s.expectedOptions, options) + return s.fn(prompt, defaultValue, options) +} + +func (m *PrompterMock) MultiSelect(prompt string, defaultValues, options []string) ([]int, error) { + var s multiSelectStub + if len(m.multiSelectStubs) == 0 { + return []int{}, noSuchPromptErr(prompt) + } + s = m.multiSelectStubs[0] + m.multiSelectStubs = m.multiSelectStubs[1:len(m.multiSelectStubs)] + if s.prompt != prompt { + return []int{}, noSuchPromptErr(prompt) + } + assertOptions(m.t, s.expectedOptions, options) + return s.fn(prompt, defaultValues, options) +} + +func (m *PrompterMock) Input(prompt, defaultValue string) (string, error) { + var s inputStub + if len(m.inputStubs) == 0 { + return "", noSuchPromptErr(prompt) + } + s = m.inputStubs[0] + m.inputStubs = m.inputStubs[1:len(m.inputStubs)] + if s.prompt != prompt { + return "", noSuchPromptErr(prompt) + } + return s.fn(prompt, defaultValue) +} + +func (m *PrompterMock) Password(prompt string) (string, error) { + var s passwordStub + if len(m.passwordStubs) == 0 { + return "", noSuchPromptErr(prompt) + } + s = m.passwordStubs[0] + m.passwordStubs = m.passwordStubs[1:len(m.passwordStubs)] + if s.prompt != prompt { + return "", noSuchPromptErr(prompt) + } + return s.fn(prompt) +} + +func (m *PrompterMock) Confirm(prompt string, defaultValue bool) (bool, error) { + var s confirmStub + if len(m.confirmStubs) == 0 { + return false, noSuchPromptErr(prompt) + } + s = m.confirmStubs[0] + m.confirmStubs = m.confirmStubs[1:len(m.confirmStubs)] + if s.Prompt != prompt { + return false, noSuchPromptErr(prompt) + } + return s.Fn(prompt, defaultValue) +} + +func (m *PrompterMock) RegisterSelect(prompt string, opts []string, stub func(_, _ string, _ []string) (int, error)) { + m.selectStubs = append(m.selectStubs, selectStub{ + prompt: prompt, + expectedOptions: opts, + fn: stub}) +} + +func (m *PrompterMock) RegisterMultiSelect(prompt string, d, opts []string, stub func(_ string, _, _ []string) ([]int, error)) { + m.multiSelectStubs = append(m.multiSelectStubs, multiSelectStub{ + prompt: prompt, + expectedOptions: opts, + fn: stub}) +} + +func (m *PrompterMock) RegisterInput(prompt string, stub func(_, _ string) (string, error)) { + m.inputStubs = append(m.inputStubs, inputStub{prompt: prompt, fn: stub}) +} + +func (m *PrompterMock) RegisterPassword(prompt string, stub func(string) (string, error)) { + m.passwordStubs = append(m.passwordStubs, passwordStub{prompt: prompt, fn: stub}) +} + +func (m *PrompterMock) RegisterConfirm(prompt string, stub func(_ string, _ bool) (bool, error)) { + m.confirmStubs = append(m.confirmStubs, confirmStub{Prompt: prompt, Fn: stub}) +} + +func (m *PrompterMock) verify() { + errs := []string{} + if len(m.selectStubs) > 0 { + errs = append(errs, "MultiSelect") + } + if len(m.multiSelectStubs) > 0 { + errs = append(errs, "Select") + } + if len(m.inputStubs) > 0 { + errs = append(errs, "Input") + } + if len(m.passwordStubs) > 0 { + errs = append(errs, "Password") + } + if len(m.confirmStubs) > 0 { + errs = append(errs, "Confirm") + } + if len(errs) > 0 { + m.t.Helper() + m.t.Errorf("%d unmatched calls to %s", len(errs), strings.Join(errs, ",")) + } +} + +func noSuchPromptErr(prompt string) error { + return fmt.Errorf("no such prompt '%s'", prompt) +} + +func assertOptions(t *testing.T, expected, actual []string) { + assert.Equal(t, expected, actual) +} diff --git a/pkg/prompter/prompter.go b/pkg/prompter/prompter.go new file mode 100644 index 0000000..8f55612 --- /dev/null +++ b/pkg/prompter/prompter.go @@ -0,0 +1,123 @@ +package prompter + +import ( + "fmt" + "io" + "strings" + + "github.com/AlecAivazis/survey/v2" + "github.com/cli/go-gh/v2/pkg/text" +) + +type Prompter struct { + stdin FileReader + stdout FileWriter + stderr FileWriter +} + +type FileWriter interface { + io.Writer + Fd() uintptr +} + +type FileReader interface { + io.Reader + Fd() uintptr +} + +func New(stdin FileReader, stdout FileWriter, stderr FileWriter) *Prompter { + return &Prompter{ + stdin: stdin, + stdout: stdout, + stderr: stderr, + } +} + +func (p *Prompter) Select(prompt, defaultValue string, options []string) (int, error) { + var result int + q := &survey.Select{ + Message: prompt, + Options: options, + PageSize: 20, + Filter: latinMatchingFilter, + } + if defaultValue != "" { + for _, o := range options { + if o == defaultValue { + q.Default = defaultValue + break + } + } + } + err := p.ask(q, &result) + return result, err +} + +func (p *Prompter) MultiSelect(prompt string, defaultValues, options []string) ([]int, error) { + var result []int + q := &survey.MultiSelect{ + Message: prompt, + Options: options, + PageSize: 20, + Filter: latinMatchingFilter, + } + if len(defaultValues) > 0 { + validatedDefault := []string{} + for _, x := range defaultValues { + for _, y := range options { + if x == y { + validatedDefault = append(validatedDefault, x) + } + } + } + q.Default = validatedDefault + } + err := p.ask(q, &result) + return result, err +} + +func (p *Prompter) Input(prompt, defaultValue string) (string, error) { + var result string + err := p.ask(&survey.Input{ + Message: prompt, + Default: defaultValue, + }, &result) + return result, err +} + +func (p *Prompter) Password(prompt string) (string, error) { + var result string + err := p.ask(&survey.Password{ + Message: prompt, + }, &result) + return result, err +} + +func (p *Prompter) Confirm(prompt string, defaultValue bool) (bool, error) { + var result bool + err := p.ask(&survey.Confirm{ + Message: prompt, + Default: defaultValue, + }, &result) + return result, err +} + +func (p *Prompter) ask(q survey.Prompt, response interface{}, opts ...survey.AskOpt) error { + opts = append(opts, survey.WithStdio(p.stdin, p.stdout, p.stderr)) + err := survey.AskOne(q, response, opts...) + if err == nil { + return nil + } + return fmt.Errorf("could not prompt: %w", err) +} + +// LatinMatchingFilter returns whether the value matches the input filter. +// The strings are compared normalized in case. +// The filter's diactritics are kept as-is, but the value's are normalized, +// so that a missing diactritic in the filter still returns a result. +func latinMatchingFilter(filter, value string, index int) bool { + filter = strings.ToLower(filter) + value = strings.ToLower(value) + // include this option if it matches. + return strings.Contains(value, filter) || strings.Contains(text.RemoveDiacritics(value), filter) +} diff --git a/pkg/prompter/prompter_test.go b/pkg/prompter/prompter_test.go new file mode 100644 index 0000000..2c771f5 --- /dev/null +++ b/pkg/prompter/prompter_test.go @@ -0,0 +1,76 @@ +package prompter + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestLatinMatchingFilter(t *testing.T) { + tests := []struct { + name string + filter string + value string + want bool + }{ + { + name: "exact match no diacritics", + filter: "Mikelis", + value: "Mikelis", + want: true, + }, + { + name: "exact match no diacritics", + filter: "Mikelis", + value: "Mikelis", + want: true, + }, + { + name: "exact match diacritics", + filter: "Miķelis", + value: "Miķelis", + want: true, + }, + { + name: "partial match diacritics", + filter: "Miķe", + value: "Miķelis", + want: true, + }, + { + name: "exact match diacritics in value", + filter: "Mikelis", + value: "Miķelis", + want: true, + }, + { + name: "partial match diacritics in filter", + filter: "Miķe", + value: "Miķelis", + want: true, + }, + { + name: "no match when removing diacritics in filter", + filter: "Mielis", + value: "Mikelis", + want: false, + }, + { + name: "no match when removing diacritics in value", + filter: "Mikelis", + value: "Mielis", + want: false, + }, + { + name: "no match diacritics in filter", + filter: "Miķelis", + value: "Mikelis", + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, latinMatchingFilter(tt.filter, tt.value, 0), tt.want) + }) + } +} diff --git a/pkg/text/text.go b/pkg/text/text.go index 586d5b4..dfd3be6 100644 --- a/pkg/text/text.go +++ b/pkg/text/text.go @@ -6,9 +6,13 @@ import ( "regexp" "strings" "time" + "unicode" "github.com/muesli/reflow/ansi" "github.com/muesli/reflow/truncate" + "golang.org/x/text/runes" + "golang.org/x/text/transform" + "golang.org/x/text/unicode/norm" ) const ( @@ -84,3 +88,19 @@ func RelativeTimeAgo(a, b time.Time) string { return fmtDuration(int(ago.Hours()/24/365), "year") } + +// RemoveDiacritics returns the input value without "diacritics", or accent marks. +func RemoveDiacritics(value string) string { + // Mn = "Mark, nonspacing" unicode character category + removeMnTransfomer := runes.Remove(runes.In(unicode.Mn)) + + // 1. Decompose the text into characters and diacritical marks + // 2. Remove the diacriticals marks + // 3. Recompose the text + t := transform.Chain(norm.NFD, removeMnTransfomer, norm.NFC) + normalized, _, err := transform.String(t, value) + if err != nil { + return value + } + return normalized +} diff --git a/pkg/text/text_test.go b/pkg/text/text_test.go index d8c4a1d..e11cbd2 100644 --- a/pkg/text/text_test.go +++ b/pkg/text/text_test.go @@ -304,3 +304,57 @@ func TestIndent(t *testing.T) { }) } } + +func TestRemoveDiacritics(t *testing.T) { + tests := [][]string{ + // no diacritics + {"e", "e"}, + {"و", "و"}, + {"И", "И"}, + {"ж", "ж"}, + {"私", "私"}, + {"万", "万"}, + + // diacritics test sets + {"à", "a"}, + {"é", "e"}, + {"è", "e"}, + {"ô", "o"}, + {"ᾳ", "α"}, + {"εͅ", "ε"}, + {"ῃ", "η"}, + {"ιͅ", "ι"}, + + {"ؤ", "و"}, + + {"ā", "a"}, + {"č", "c"}, + {"ģ", "g"}, + {"ķ", "k"}, + {"ņ", "n"}, + {"š", "s"}, + {"ž", "z"}, + + {"ŵ", "w"}, + {"ŷ", "y"}, + {"ä", "a"}, + {"ÿ", "y"}, + {"á", "a"}, + {"ẁ", "w"}, + {"ỳ", "y"}, + {"ō", "o"}, + + // full words + {"Miķelis", "Mikelis"}, + {"François", "Francois"}, + {"žluťoučký", "zlutoucky"}, + {"învățătorița", "invatatorita"}, + {"Kękę przy łóżku", "Keke przy łozku"}, + } + + for _, tt := range tests { + t.Run(RemoveDiacritics(tt[0]), func(t *testing.T) { + assert.Equal(t, tt[1], RemoveDiacritics(tt[0])) + }) + } +}