Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone committed Aug 27, 2020
1 parent 7034b9b commit 0104557
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions internal/core/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,21 @@ func (p *Printer) printTemplate(data interface{}) error {
_, isError := data.(error)
if isError {
writer = p.stderr
return p.printHuman(data, nil)
}

dataType := reflect.TypeOf(data)
dataValue := reflect.ValueOf(data)
switch dataType.Kind() {
switch dataValue.Type().Kind() {
// If we have a slice of value, we apply the template for each item
case reflect.Slice:
elemType := dataType.Elem()
for i := 0; i < dataValue.Len(); i++ {
elemValue := dataValue.Index(i)
err := p.template.Execute(writer, elemValue)
if err != nil {
return &CliError{
Err: fmt.Errorf("templating error. Acceptable values are %s", strings.Join(gofields.ListFields(elemType), ",")),
}
return p.printHuman(&CliError{
Err: fmt.Errorf("templating error"),
Hint: fmt.Sprintf("Acceptable values are:\n - %s", strings.Join(gofields.ListFields(elemValue.Type()), "\n - ")),
}, nil)
}
_, _ = writer.Write([]byte{'\n'})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️
templating error. Acceptable values are [ID Name]
Templating error

Hint:
Acceptable values are:
- ID
- Name
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
[
{
Expand Down

0 comments on commit 0104557

Please sign in to comment.