Skip to content

Commit

Permalink
chore: update deps and update some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 16, 2022
1 parent 438e1e4 commit 2490e60
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
4 changes: 2 additions & 2 deletions gflag/ext_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ func (s *EnumString) Set(value string) error {
// c.VarOpt(&names, "names", "", "multi name by comma split")
//
// --names "tom,john,joy"
// names.Split(",") -> []string{"tom","john","joy"}
// names.Split(",") -> []string{"tom","john","joy"}
//
// // case 2:
// var ids gcli.String
// c.VarOpt(&ids, "ids", "", "multi id by comma split")
//
// --names "23,34,56"
// names.Ints(",") -> []int{23,34,56}
// names.Ints(",") -> []int{23,34,56}
type String string

// Set value
Expand Down
41 changes: 25 additions & 16 deletions gflag/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/gookit/goutil/strutil"
)

// CliOpts cli options manage TODO
// CliOpts cli options management
type CliOpts struct {
// name inherited from gcli.Command
name string
Expand Down Expand Up @@ -116,12 +116,12 @@ func (ops *CliOpts) float64Opt(p *float64, opt *CliOpt) {
// --- string option

// Str binding an string option flag, return pointer
func (ops *CliOpts) Str(name, shorts string, defValue, desc string) *string {
opt := newCliOpt(name, desc, defValue, shorts)
func (ops *CliOpts) Str(name, shorts string, defVal, desc string) *string {
opt := newCliOpt(name, desc, defVal, shorts)
name = ops.checkFlagInfo(opt)

// binding option to flag.FlagSet
p := ops.fSet.String(name, defValue, opt.Desc)
p := ops.fSet.String(name, defVal, opt.Desc)
opt.flag = ops.fSet.Lookup(name)

return p
Expand All @@ -131,8 +131,17 @@ func (ops *CliOpts) Str(name, shorts string, defValue, desc string) *string {
func (ops *CliOpts) StrVar(p *string, opt *CliOpt) { ops.strOpt(p, opt) }

// StrOpt binding an string option
func (ops *CliOpts) StrOpt(p *string, name, shorts, defValue, desc string) {
ops.strOpt(p, newCliOpt(name, desc, defValue, shorts))
func (ops *CliOpts) StrOpt(p *string, name, shorts string, defValWithDesc ...string) {
var defVal, desc string
if ln := len(defValWithDesc); ln > 0 {
if ln >= 2 {
defVal, desc = defValWithDesc[0], defValWithDesc[1]
} else { // only one as desc
desc = defValWithDesc[0]
}
}

ops.strOpt(p, newCliOpt(name, desc, defVal, shorts))
}

// binding option and shorts
Expand All @@ -148,12 +157,12 @@ func (ops *CliOpts) strOpt(p *string, opt *CliOpt) {
// --- intX option

// Int binding an int option flag, return pointer
func (ops *CliOpts) Int(name, shorts string, defValue int, desc string) *int {
opt := newCliOpt(name, desc, defValue, shorts)
func (ops *CliOpts) Int(name, shorts string, defVal int, desc string) *int {
opt := newCliOpt(name, desc, defVal, shorts)
name = ops.checkFlagInfo(opt)

// binding option to flag.FlagSet
ptr := ops.fSet.Int(name, defValue, opt.Desc)
ptr := ops.fSet.Int(name, defVal, opt.Desc)
opt.flag = ops.fSet.Lookup(name)

return ptr
Expand All @@ -163,26 +172,26 @@ func (ops *CliOpts) Int(name, shorts string, defValue int, desc string) *int {
func (ops *CliOpts) IntVar(ptr *int, opt *CliOpt) { ops.intOpt(ptr, opt) }

// IntOpt binding an int option
func (ops *CliOpts) IntOpt(ptr *int, name, shorts string, defValue int, desc string) {
ops.intOpt(ptr, newCliOpt(name, desc, defValue, shorts))
func (ops *CliOpts) IntOpt(ptr *int, name, shorts string, defVal int, desc string) {
ops.intOpt(ptr, newCliOpt(name, desc, defVal, shorts))
}

func (ops *CliOpts) intOpt(ptr *int, opt *CliOpt) {
defValue := opt.DValue().Int()
defVal := opt.DValue().Int()
name := ops.checkFlagInfo(opt)

// binding option to flag.FlagSet
ops.fSet.IntVar(ptr, name, defValue, opt.Desc)
ops.fSet.IntVar(ptr, name, defVal, opt.Desc)
opt.flag = ops.fSet.Lookup(name)
}

// Int64 binding an int64 option flag, return pointer
func (ops *CliOpts) Int64(name, shorts string, defValue int64, desc string) *int64 {
opt := newCliOpt(name, desc, defValue, shorts)
func (ops *CliOpts) Int64(name, shorts string, defVal int64, desc string) *int64 {
opt := newCliOpt(name, desc, defVal, shorts)
name = ops.checkFlagInfo(opt)

// binding option to flag.FlagSet
p := ops.fSet.Int64(name, defValue, opt.Desc)
p := ops.fSet.Int64(name, defVal, opt.Desc)
opt.flag = ops.fSet.Lookup(name)

return p
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/gookit/color v1.5.2
github.com/gookit/goutil v0.5.12
github.com/gookit/goutil v0.5.14
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
)

Expand All @@ -13,5 +13,5 @@ require (
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/text v0.3.8 // indirect
)
25 changes: 22 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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=
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.5.12 h1:dcgIGLF1uBUTbjz0kBBL0LESMznthetAf1jQwFysNwU=
github.com/gookit/goutil v0.5.12/go.mod h1:6vhWm/bSYXGE8poqFbFz6IGM7jV2r6qVhyK567SX/AI=
github.com/gookit/goutil v0.5.14 h1:8TicCMSkpARD11SpiGJnRzUt2z3CTu+0YAq/zj2Yoag=
github.com/gookit/goutil v0.5.14/go.mod h1:ozPE16eJS9f89aVbVk05ocEJsia3KPrYUqPTs8GvUTw=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -16,23 +16,42 @@ 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/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
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/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/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-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
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-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/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-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-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
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/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.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
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/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

0 comments on commit 2490e60

Please sign in to comment.