add support for custom flag types via flag.Value
- Dominant language
- Go
- Stars
- 52
- Forks
- 45
- PR merge metrics
- No merged PRs in 30d
Description
A number of flag types are supported: https://github.com/ipfs/go-ipfs-cmds/blob/4ade007405e5d3befb14184290576c63cc43a6a3/option.go#L178-L198
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](https://github.com/ipfs/go-ipfs/commit/fcae03f58aba40e85f1a189e38cf82a3844d8660) 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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in option.go around the supported flag types and read the current option parsing logic. Trace how a flag.Value-compatible custom type would fit without using the flag package for parsing, then verify that a multicodec.Code-like value can be passed directly while existing flag options remain compatible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100