A number of flag types are supported:
|
func BoolOption(names ...string) Option { |
|
return NewOption(Bool, names...) |
|
} |
|
func IntOption(names ...string) Option { |
|
return NewOption(Int, names...) |
|
} |
|
func UintOption(names ...string) Option { |
|
return NewOption(Uint, names...) |
|
} |
|
func Int64Option(names ...string) Option { |
|
return NewOption(Int64, names...) |
|
} |
|
func Uint64Option(names ...string) Option { |
|
return NewOption(Uint64, names...) |
|
} |
|
func FloatOption(names ...string) Option { |
|
return NewOption(Float, names...) |
|
} |
|
func StringOption(names ...string) Option { |
|
return NewOption(String, names...) |
|
} |
This mostly mirrors what https://pkg.go.dev/flag supports, with one notable exception: flag.Value via https://pkg.go.dev/flag#Var.
This is very useful for custom types which know how to be used as flags. For example: https://pkg.go.dev/github.com/multiformats/go-multicodec@master#Code.Set
Right now, if I want a go-ipfs tool to have a multicodec.Code flag, I have to use StringOption, and then separately write about 4 lines of extra code to translate that via a Code.Set call. It would be much easier to be able to use it directly, via a go-ipfs-cmds API like VarOption or FlagValueOption.
Note that this does not require using the flag package for parsing arguments or flags. flag.Value is an interface, so it should be compatible with the current logic: https://pkg.go.dev/flag#Value
cc @willscott @masih
A number of flag types are supported:
go-ipfs-cmds/option.go
Lines 178 to 198 in 4ade007
This mostly mirrors what https://pkg.go.dev/flag supports, with one notable exception:
flag.Valuevia https://pkg.go.dev/flag#Var.This is very useful for custom types which know how to be used as flags. For example: https://pkg.go.dev/github.com/multiformats/go-multicodec@master#Code.Set
Right now, if I want a go-ipfs tool to have a
multicodec.Codeflag, I have to useStringOption, and then separately write about 4 lines of extra code to translate that via aCode.Setcall. It would be much easier to be able to use it directly, via a go-ipfs-cmds API likeVarOptionorFlagValueOption.Note that this does not require using the flag package for parsing arguments or flags.
flag.Valueis an interface, so it should be compatible with the current logic: https://pkg.go.dev/flag#Valuecc @willscott @masih