-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for custom flag types via flag.Value #213
Comments
This comment has been minimized.
This comment has been minimized.
The linked PR above would also benefit from this :) |
I would love for this to happen, but, FYI, there are eldritch dragons here. If you can find a way to make this work with, e.g., our But I figured I'd warn you. At the very lease, please try to avoid major refactors because I've reviewed at least 3 refactors here and all of them have been... difficult (race conditions, strange edge cases, etc). |
I don't know if this is helpful or not but I ended up writing a small library specifically to skirt around this. In particular I wanted to be able to add a field Screencast of the initial phase: https://www.youtube.com/watch?v=6oGsKnfZFzA and slightly later https://www.youtube.com/watch?v=7LI0_EequHA I'm planning to extend this soon so that a config file can be used as a source and I won't have to change anything in any of the the |
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.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 useStringOption
, and then separately write about 4 lines of extra code to translate that via aCode.Set
call. It would be much easier to be able to use it directly, via a go-ipfs-cmds API likeVarOption
orFlagValueOption
.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#Valuecc @willscott @masih
The text was updated successfully, but these errors were encountered: