-
Notifications
You must be signed in to change notification settings - Fork 1k
Status template output #1389
Status template output #1389
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"html/template" | ||
"io" | ||
"io/ioutil" | ||
"log" | ||
|
@@ -191,6 +192,25 @@ func (out *dotOutput) MissingHeader() {} | |
func (out *dotOutput) MissingLine(ms *MissingStatus) {} | ||
func (out *dotOutput) MissingFooter() {} | ||
|
||
type templateOutput struct { | ||
w io.Writer | ||
tmpl *template.Template | ||
} | ||
|
||
func (out *templateOutput) BasicHeader() {} | ||
func (out *templateOutput) BasicFooter() {} | ||
|
||
func (out *templateOutput) BasicLine(bs *BasicStatus) { | ||
out.tmpl.Execute(out.w, bs) | ||
} | ||
|
||
func (out *templateOutput) MissingHeader() {} | ||
func (out *templateOutput) MissingFooter() {} | ||
|
||
func (out *templateOutput) MissingLine(ms *MissingStatus) { | ||
out.tmpl.Execute(out.w, ms) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the same template for There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 A non-templateOutput status with missing packages error looks like this.
When the user does Is there some use-case that I'm overlooking? 🤔 |
||
} | ||
|
||
func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error { | ||
p, err := ctx.LoadProject() | ||
if err != nil { | ||
|
@@ -231,6 +251,15 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error { | |
o: cmd.output, | ||
w: &buf, | ||
} | ||
case cmd.template != "": | ||
tmpl, err := template.New("status").Parse(cmd.template) | ||
if err != nil { | ||
return err | ||
} | ||
out = &templateOutput{ | ||
w: &buf, | ||
tmpl: tmpl, | ||
} | ||
default: | ||
out = &tableOutput{ | ||
w: tabwriter.NewWriter(&buf, 0, 4, 2, ' ', 0), | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[[constraint]] | ||
name = "github.com/sdboyer/deptest" | ||
version = "^0.8.0" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[[constraint]] | ||
name = "github.com/sdboyer/deptest" | ||
version = "^0.8.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2016 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/sdboyer/deptest" | ||
"github.com/sdboyer/deptestdos" | ||
) | ||
|
||
func main() { | ||
err := nil | ||
if err != nil { | ||
deptest.Map["yo yo!"] | ||
} | ||
deptestdos.diMeLo("whatev") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PROJECT: github.com/sdboyer/deptest, VERSION: v0.8.0 | ||
PROJECT: github.com/sdboyer/deptestdos, VERSION: v2.0.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"commands": [ | ||
["ensure"], | ||
["status", "-f=PROJECT: {{.ProjectRoot}}, VERSION: {{.Version}}\n"] | ||
], | ||
"error-expected": "", | ||
"vendor-final": [ | ||
"github.com/sdboyer/deptest", | ||
"github.com/sdboyer/deptestdos" | ||
] | ||
} |
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.
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 toout.w
or routed toctx.Out/Err
. MaybeErr
, to cleanly separate it for anything parsing.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.
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()
intableOutput
andjson.Encode()
injsonOutput
. 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.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.
@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.