Skip to content

Commit

Permalink
chore: update deps and add tests on go1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Feb 2, 2023
1 parent 24474f7 commit c1a77a9
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go_version: [1.18, 1.19]
go_version: [1.18, 1.19, 1.20]

steps:
- name: Check out codes
Expand Down
2 changes: 1 addition & 1 deletion _examples/cmd/interact_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ var InteractCollectCmd = &gcli.Command{
err := vc.AddParams(
cparam.NewStringParam("title", "title name").Config(func(p *cparam.StringParam) {
p.ValidFn = func(val string) error {
return goutil.ErrOnFail(strutil.IsBlank(val), errorx.Raw("title is required"))
return goutil.OrError(strutil.IsBlank(val), errorx.Raw("title is required"))
}
}),
cparam.NewChoiceParam("projects", "select projects").
Expand Down
10 changes: 10 additions & 0 deletions gflag/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func (ops *CliOpts) BoolOpt(ptr *bool, name, shorts string, defVal bool, desc st
ops.boolOpt(ptr, newCliOpt(name, desc, defVal, shorts))
}

// BoolOpt2 binding a bool option, and allow with CliOptFn for config option.
func (ops *CliOpts) BoolOpt2(p *bool, nameWithShorts, desc string, confFuncs ...CliOptFn) {
opt := &CliOpt{Name: nameWithShorts, Desc: desc, DefVal: false}
for _, optFn := range confFuncs {
optFn(opt)
}

ops.boolOpt(p, opt)
}

// binding option and shorts
func (ops *CliOpts) boolOpt(ptr *bool, opt *CliOpt) {
defVal := opt.DValue().Bool()
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ go 1.18

require (
github.com/gookit/color v1.5.2
github.com/gookit/goutil v0.6.1
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035
github.com/gookit/goutil v0.6.2
golang.org/x/crypto v0.5.0
golang.org/x/term v0.4.0
)

require (
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/gookit/color v1.5.2 h1:uLnfXcaFjlrDnQDT+NCBcfhrXqYTx/rcCa6xn01Y8yI=
github.com/gookit/color v1.5.2/go.mod h1:w8h4bGiHeeBpvQVePTutdbERIUf3oJE5lZ8HM0UgXyg=
github.com/gookit/goutil v0.6.1 h1:EsaMR1QWxg61R8oBW7sbSHUxQzMZUKTDUEAKpsHUXJI=
github.com/gookit/goutil v0.6.1/go.mod h1:s2xa6+NP2nxI+h88TUAio7xROJzZaerEfkzJ0+lqvm4=
github.com/gookit/goutil v0.6.2 h1:vOf6wc5nDGHElUlr0cYJNhxtCbNfq9Z0oSg4Ih2gDNI=
github.com/gookit/goutil v0.6.2/go.mod h1:mdJ/GPQzbbKtNhwxOsXNBRAbF2+UE/HdRhELlG7btXU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -14,17 +16,27 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 h1:v6hYoSR9T5oet+pMXwUWkbiVqx/63mlHjefrHmxwfeY=
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg=
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
61 changes: 61 additions & 0 deletions interact/cparam/multi_choices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cparam

import (
"github.com/gookit/gcli/v3/interact"
"github.com/gookit/goutil/errorx"
)

// ChoicesParam definition
type ChoicesParam struct {
InputParam
// Choices for select
Choices []string
selected []string
}

// NewChoicesParam instance
func NewChoicesParam(name, desc string) *ChoicesParam {
return &ChoicesParam{
InputParam: InputParam{
typ: TypeChoicesParam,
name: name,
desc: desc,
},
}
}

// WithChoices to param definition
func (p *ChoicesParam) WithChoices(Choices []string) *ChoicesParam {
p.Choices = Choices
return p
}

// Selected values get
func (p *ChoicesParam) Selected() []string {
return p.val.Strings()
}

// Set value
func (p *ChoicesParam) Set(v string) error {
if err := p.Valid(v); err != nil {
return err
}

p.selected = append(p.selected, v)
p.val.Set(p.selected)
return nil
}

// Run param and get user input
func (p *ChoicesParam) Run() (err error) {
if len(p.Choices) == 0 {
return errorx.Raw("must provide items for choices")
}

s := interact.NewSelect(p.Desc(), p.Choices)
s.EnableMulti()

sr := s.Run()
p.val.Set(sr.Val())
return
}

0 comments on commit c1a77a9

Please sign in to comment.