Add multiple output printer formats - #22
Conversation
| RenderDetail(obj, fields, labels) | ||
| case "json": | ||
| if msg, ok := obj.(proto.Message); ok { | ||
| m := jsonpb.Marshaler{Indent: " "} |
There was a problem hiding this comment.
probably wanna use utilv1's marshaler or copy it https://github.com/confluentinc/cc-structs/blob/master/kafka/util/v1/codec.go#L23-L27
|
type per view would be a lot simpler, cleaner, flexible. add a dash of generating to save the duping if necessary. |
Joshua Buss (chicagobuss)
left a comment
There was a problem hiding this comment.
lgtm, but could you make a test or two to make sure you're getting the output you expect?
|
|
||
| func (f *enumStringifyingFieldMaker) MakeField(oldType reflect.Type, newType reflect.Type, oldTag reflect.StructTag, newTag reflect.StructTag) (reflect.Type, reflect.StructTag) { | ||
| if strings.Contains(string(oldTag), "protobuf:") && strings.Contains(string(oldTag), "enum=") { | ||
| newType = reflect.TypeOf("") |
There was a problem hiding this comment.
surely there's an easier way to get a string type?
|
|
||
| type enumStringifyingFieldMaker struct{} | ||
|
|
||
| func (f *enumStringifyingFieldMaker) MakeField(oldType reflect.Type, newType reflect.Type, oldTag reflect.StructTag, newTag reflect.StructTag) (reflect.Type, reflect.StructTag) { |
There was a problem hiding this comment.
Would like a walkthrough of how exactly this works sometime...
|
|
||
| // Helper which stringifies protobuf enum fields. | ||
| // Implemented by returning an anonymous dynamic struct with string field type in place of enum fields. | ||
| func prepareProtoStruct(msg proto.Message, fields []string) interface{} { |
There was a problem hiding this comment.
yah, I think I needed this in the last app I was trying to make, too
|
Joshua Buss (@chicagobuss) tests added. bugs fixed |
* chore: reset mk-include * Squashed 'mk-include/' content from commit 040d48f git-subtree-dir: mk-include git-subtree-split: 040d48f663b65e28ed3463e4bffe2e4b52f4a2f4 * chore: add mk-include-git-hash --------- Co-authored-by: Confluent Jenkins Bot <jenkins@confluent.io>
We'd like to be able to support
-o yaml,-o json,-o wide, etc. Much likekubectldoes.Specifically,
I used the retag library for #1 and #2. Basically, I just change the struct tag to the new name/label or to "-" to drop it from the view.
But
retagdoesn't work for #3 since it just uses the actual struct field type (which is int32 for enums). So I forked the library to make it a bit more generic so we can actually change the struct field type as well. Of course, this makes the structs not in-memory compatible but that doesn't matter as long as you make a copy instead of just trying to update the original pointer.This makes creating a new CLI view very simple. Just pass the fields you want, labels you want (for renaming fields), and the desired output format:
Here's how it looks for a connect cluster (both JSON and YAML):