Conversation
With the `--format` flag, the value of the flag is parsed as a Go template which is then evaluated against parsed response data. https://golang.org/pkg/text/template
vilmibm
left a comment
There was a problem hiding this comment.
This is really cool!
Is it alright to expose Go templates to the user here?
I'm torn on this but I think it's for the best. To try and present something simpler means we'd need to maintain our own little templating language; I prefer the idea of adopting something else. It is a fair bit of cognitive overhead though and pretty verbose as far as template languages go. I'm curious what @ampinsk thinks.
Is the -t, --format flag naming okay? Should it be -t, --template instead?
If -f is already taken I'd vote for -t and --template for consistency.
For passing in more complex templates, should we additionally accept a template read from a file?
This is a reasonable improvement but I don't think needs to be in the first ship if you want to put it off.
Are there any other formatting functions like color we should add for the initial ship?
Color is a great place to start; it will be easier to guess what other functions we might want once it's in use. I suspect something around managing alignment (beyond raw tab characters) could be useful but I'm not exactly sure what that would look like yet.
|
@mislav should I be reviewing this PR in full yet? |
|
@vilmibm Later today please! I'm working on adding documentation to this first. |
vilmibm
left a comment
There was a problem hiding this comment.
I love this feature and its implementation as well as the set of initial tempalate functions you went with.
Question: you mention mgutz/ansi; does this mean no color support on Windows?
as far as changes, I'd like to see a few more tests:
- golden path for using
-twithgh api - tests that exercise the default template functions; I see pluck and join but none of the other functions present in tests. Even if we're not actually checking color codes it's good to verify that we're exposing those functions correctly the the template engine.
All ANSI escape sequences are automatically converted to correct color codes on Windows by nature of our IOStreams object.
Added more tests! |
The
--formatflag accepts a Go template string that the resulting data will be formatted with instead of being output as JSON.Example:
Output:

Discuss:
-t, --formatflag naming okay? Should it be-t, --templateinstead?colorwe should add for the initial ship?TODO:
colorcolorhelper variant that only outputs ANSI color sequences when outputting to a tty