Skip to content

Commit

Permalink
bugfix: fix error when input 'inspect -f {{.Id}}'
Browse files Browse the repository at this point in the history
Signed-off-by: KevinBetterQ <1093850932@qq.com>
  • Loading branch information
KevinBetterQ committed May 19, 2019
1 parent 7235f82 commit c4c3de0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cli/inspect/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func NewTemplateInspectorFromString(out io.Writer, tmplStr string) (Inspector, e
if tmplStr == "" {
return NewIndentedInspector(out), nil
}
if strings.Contains(tmplStr, ".Id") {
tmplStr = strings.Replace(tmplStr, ".Id", ".ID", -1)
}

tmpl, err := templates.Parse(tmplStr)
if err != nil {
Expand Down
11 changes: 10 additions & 1 deletion cli/inspect/inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,20 @@ func TestInspect(t *testing.T) {
},
wantOut: "\n",
wantErr: false,
}, {
name: "testInspectTemplate{{.Id}}",
args: args{
references: []string{"reference"},
tmplStr: "{{.Id}}",
getRef: getRefFunc,
},
wantOut: "id",
wantErr: false,
}, {
name: "testInspectTemplateError",
args: args{
references: []string{"single reference"},
tmplStr: "{{.Id}}",
tmplStr: "{{.id}}",
getRef: getRefFunc,
},
wantOut: "",
Expand Down

0 comments on commit c4c3de0

Please sign in to comment.