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

Commit 44d8995

Browse files
authored
Merge pull request #1389 from darkowlzz/status-template-output
Status template output
2 parents 26f91c7 + 8a9cea3 commit 44d8995

File tree

8 files changed

+100
-0
lines changed

8 files changed

+100
-0
lines changed

cmd/dep/status.go

+29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/json"
1010
"flag"
1111
"fmt"
12+
"html/template"
1213
"io"
1314
"io/ioutil"
1415
"log"
@@ -190,6 +191,25 @@ func (out *dotOutput) MissingHeader() {}
190191
func (out *dotOutput) MissingLine(ms *MissingStatus) {}
191192
func (out *dotOutput) MissingFooter() {}
192193

194+
type templateOutput struct {
195+
w io.Writer
196+
tmpl *template.Template
197+
}
198+
199+
func (out *templateOutput) BasicHeader() {}
200+
func (out *templateOutput) BasicFooter() {}
201+
202+
func (out *templateOutput) BasicLine(bs *BasicStatus) {
203+
out.tmpl.Execute(out.w, bs)
204+
}
205+
206+
func (out *templateOutput) MissingHeader() {}
207+
func (out *templateOutput) MissingFooter() {}
208+
209+
func (out *templateOutput) MissingLine(ms *MissingStatus) {
210+
out.tmpl.Execute(out.w, ms)
211+
}
212+
193213
func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
194214
p, err := ctx.LoadProject()
195215
if err != nil {
@@ -230,6 +250,15 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
230250
o: cmd.output,
231251
w: &buf,
232252
}
253+
case cmd.template != "":
254+
tmpl, err := template.New("status").Parse(cmd.template)
255+
if err != nil {
256+
return err
257+
}
258+
out = &templateOutput{
259+
w: &buf,
260+
tmpl: tmpl,
261+
}
233262
default:
234263
out = &tableOutput{
235264
w: tabwriter.NewWriter(&buf, 0, 4, 2, ' ', 0),

cmd/dep/testdata/harness_tests/status/case1/template/final/Gopkg.lock

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[constraint]]
2+
name = "github.com/sdboyer/deptest"
3+
version = "^0.8.0"

cmd/dep/testdata/harness_tests/status/case1/template/initial/Gopkg.lock

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[constraint]]
2+
name = "github.com/sdboyer/deptest"
3+
version = "^0.8.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"github.com/sdboyer/deptest"
9+
"github.com/sdboyer/deptestdos"
10+
)
11+
12+
func main() {
13+
err := nil
14+
if err != nil {
15+
deptest.Map["yo yo!"]
16+
}
17+
deptestdos.diMeLo("whatev")
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PROJECT: github.com/sdboyer/deptest, VERSION: v0.8.0
2+
PROJECT: github.com/sdboyer/deptestdos, VERSION: v2.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"commands": [
3+
["ensure"],
4+
["status", "-f=PROJECT: {{.ProjectRoot}}, VERSION: {{.Version}}\n"]
5+
],
6+
"error-expected": "",
7+
"vendor-final": [
8+
"github.com/sdboyer/deptest",
9+
"github.com/sdboyer/deptestdos"
10+
]
11+
}

0 commit comments

Comments
 (0)