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

Commit

Permalink
Merge pull request #1389 from darkowlzz/status-template-output
Browse files Browse the repository at this point in the history
Status template output
  • Loading branch information
sdboyer committed Nov 27, 2017
2 parents 26f91c7 + 8a9cea3 commit 44d8995
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cmd/dep/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"flag"
"fmt"
"html/template"
"io"
"io/ioutil"
"log"
Expand Down Expand Up @@ -190,6 +191,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)
}

func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
p, err := ctx.LoadProject()
if err != nil {
Expand Down Expand Up @@ -230,6 +250,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),
Expand Down

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
11 changes: 11 additions & 0 deletions cmd/dep/testdata/harness_tests/status/case1/template/testcase.json
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"
]
}

0 comments on commit 44d8995

Please sign in to comment.