Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Status template output #1389

Merged
merged 3 commits into from
Nov 27, 2017
Merged

Conversation

darkowlzz
Copy link
Collaborator

What does this do / why do we need it?

This implements -f flag in status, enabling template formatted output results.

Example usage:

$ dep status -f="PROJECT: {{.ProjectRoot}}, VERSION: {{.Version}}\n"
PROJECT: github.com/Masterminds/semver, VERSION: parse-constraints-with-dash-in-pre\nPROJECT: github.com/Masterminds/vcs, VERSION: v1.11.1\nPROJECT: github.com/armon/go-radix, VERSION: master\nPROJECT: github.com/boltdb/bolt, VERSION: v1.3.1\nPROJECT: github.com/go-yaml/yaml, VERSION: v2\nPROJECT: github.com/golang/protobuf, VERSION: master\nPROJECT: github.com/jmank88/nuts, VERSION: v0.2.0\nPROJECT: github.com/nightlyone/lockfile, VERSION: master\nPROJECT: github.com/pelletier/go-buffruneio, VERSION: v0.2.0\nPROJECT: github.com/pelletier/go-toml, VERSION: master\nPROJECT: github.com/pkg/errors, VERSION: v0.8.0\nPROJECT: github.com/sdboyer/constext, VERSION: master\nPROJECT: golang.org/x/net, VERSION: master\nPROJECT: golang.org/x/sync, VERSION: master\nPROJECT: golang.org/x/sys, VERSION: master\n

What should your reviewer look out for in this PR?

The implementation.

Do you need help or clarification on anything?

No.

Which issue(s) does this PR fix?

fixes #1374

func (out *templateOutput) MissingFooter() {}

func (out *templateOutput) MissingLine(ms *MissingStatus) {
out.tmpl.Execute(out.w, ms)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the same template for BasicLine and MissingLine makes hard to write a template that handles both.
I think that -f should only provide formatting for BasicLine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dolmen thanks for reviewing :)

I don't think there is any use-case for MissingStatus with templateOutput because MissingStatus is used only while printing the error invoked by input-digest mismatch due to missing packages. This function exists because it's required to implement the outputter interface and avoid empty output when user tries to use templateout and there's a inputs-digest mismatch due to missing packages.

A non-templateOutput status with missing packages error looks like this.

$ dep status
Lock inputs-digest mismatch due to the following packages missing from the lock:

PROJECT                MISSING PACKAGES
github.com/pkg/errors  [github.com/pkg/errors]

This happens when a new import is added. Run `dep ensure` to install the missing packages.
input-digest mismatch

When the user does $ dep status -f="some-template" only the table output in the above error message would be replaced by the template rendered content. I'm not sure if that can be useful rendered content in any way.

Is there some use-case that I'm overlooking? 🤔

if cmd.template != "" {
templateOut = true
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is not necessary. See below.

@@ -231,6 +256,15 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
o: cmd.output,
w: &buf,
}
case templateOut:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with:

case cmd.template != "":

func (out *templateOutput) BasicFooter() {}

func (out *templateOutput) BasicLine(bs *BasicStatus) {
out.tmpl.Execute(out.w, bs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should errors be captured? Don't necessarily need to halt on error since it may not affect all lines (although go list -f does halt), but I'm not sure whether the feedback would be better in-line to out.w or routed to ctx.Out/Err. Maybe Err, to cleanly separate it for anything parsing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh! I didn't realize that it returned an error. Maybe because we are not handling the returned error in any of the other writes, like error from fmt.Fprintf() in tableOutput and json.Encode() in jsonOutput. Encoding failure seems important to handle to me.
Routing the error to Err should be better; similar to how we keep the partial status output separate from the raised errors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darkowlzz so is there a change to be made here? this was on my list to "merge fast, fail fast," but it seems like you're planning on a followup.

@sdboyer
Copy link
Member

sdboyer commented Nov 27, 2017

going to defer the error handling to a follow-up

@sdboyer sdboyer merged commit 44d8995 into golang:master Nov 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to "go install" all dependencies for Docker build caching
5 participants