snitch
snitch copied to clipboard
Use a map to store snitch argument options
This is purely a nice to have as it makes it a lot easier to access options from one general map, and error handling of arguments a lot easier. For example, with a map, checking if an option exists would be something like this:
func doA(a string) {
fmt.Println(a)
}
func doB(b string) {
fmt.Println(b)
}
func main() {
m := map[string]interface{}{
"a": doA,
"b": doB,
}
if val, ok := m[as.Args[1]]; ok {
val.(func(string))("henlo")
} else {
fmt.Println("snitch")
for k, v := range m {
fmt.Printf("\tkey[%s]\n", k, v)
}
}
}
This seems like a nice solution, but does bring interfaces and type assertion with it seen in this example.
Let me know what you think, if you like it, i will implement it for all command functions.
@fabulousduck when the PR is merged all of the TODOs it contained automatically approved. Basically, I review not only the code, but also the future issues it may introduce. And if I don't approve a particular issue I'll just simply ask to remove the TODO on the review. ;)
so just for confirmation, you agree this is a good idea ?
@fabulousduck it sounds ok to me