-
Notifications
You must be signed in to change notification settings - Fork 38
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 json to list cmd #379
Add json to list cmd #379
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just dropped some requests for minor changes on the PR.
We should also add a test. We've been using txtar/testscript for it. However, we can add the test case out of band.
internal/cmd/list.go
Outdated
} | ||
|
||
return errors.Wrap(table.Render(), "failed to render") | ||
if !isJSON { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably break these out in functions (data passed to both is the same) for json and table respectively since the listCmd
keeps growing.
internal/cmd/list.go
Outdated
}, | ||
} | ||
|
||
cmd.PersistentFlags().BoolVar(&isJSON, "json", false, "This flag tells the list command to print the output in json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename isJSON
to formatJSON
and move it into the function scope, just like here:
https://github.com/stateful/runme/blob/main/internal/cmd/fmt.go#L12-L13
Flags that are being used across commands can go into the module scope.
internal/cmd/list.go
Outdated
if err != nil { | ||
return err | ||
} | ||
err = jsonpretty.Format(io.Out, bytes.NewReader(by), " ", false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine jsonpretty
has some benefits over just writing to output? Either way, the dependency to go-gh
already exists so no harm done.
move row struct up a level
added test for json
Changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Tidied the modules and ran gofumpt ( |
This should close #380