-
Notifications
You must be signed in to change notification settings - Fork 236
Option to write output to file #275
Comments
@vsoch thanks for another good issue, I'm a +1 on this. let me know if you'd be interested in sending another PR :) in https://github.com/GoogleContainerTools/container-diff/blob/master/util/format_utils.go, we should be able to modify all the methods that actually write to func TemplateOutput(diff interface{}, templateType string) would become func TemplateOutput(out io.Writer, diff interface{}, templateType string) error then it's just a matter of creating the right writer from the entrypoint (parsing a flag for an output file, opening it for writing if it exists, otherwise passing |
I'd again love to! I appreciate the tips on the methods and how to go about it, I'll probably be a noob for a while longer. I'll see what I can figure out from your guidance and post an update either here or via a PR. |
hey @nkubala ! I'm struggling a little bit with where functions should be defined, and how variables should be passed (and their scope). If I define a function to "getWriter" in the utils package, this means that I need to pass the command line variable (a string for a file) into any corresponding functions in util (such as TemplateOutput, and all the other in the TemplateOutput*) family, and then that extends to |
hey @vsoch, sorry for the late reply here. Generally speaking, anything that consumes a top-level CLI flag should live inside the Fortunately, we already have a handy
Good question :) from the docs, Hope this was helpful! We're getting into the inner workings of how Golang handles writing to different output streams here, so let me know if you need some more guidance (or if you want me to just do this 😆) |
This is really helpful! And I'm enjoying it and learning a ton! And heck no, I want to see if I can do it, worst case scenario I'll ask for more guidance. Thank you for your help so far! I'll see if I can get a PR soon. |
I've been fairly happy with piping output into file or into a string for parsing from a program (with a custom logging setting of panic and other quiet flags) but recently ran into an issue I'm having a hard time getting around - fairly challenging use when I want to capture output in a cluster environment. When I issue the command interactively I can still capture it, but on headless nodes (where it's nontrivial to give them a display) I'm getting empty strings.
So ! Instead of diving into the buggy pit of debugging the output or this one specific cluster, I think it would be more straight forward to write directly to file. This is especially appropriate for the
--json
flag. Is there any interest here?The text was updated successfully, but these errors were encountered: