Merge pull request #624 from hashicorp/vault-i583
CLI: Avoiding CR when printing specific fields
This commit is contained in:
commit
5b6d6bf79a
|
@ -2,6 +2,8 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -55,7 +57,16 @@ func (c *ReadCommand) Run(args []string) int {
|
|||
// Handle single field output
|
||||
if field != "" {
|
||||
if val, ok := secret.Data[field]; ok {
|
||||
c.Ui.Output(val.(string))
|
||||
// c.Ui.Output() prints a CR character which in this case is
|
||||
// not desired. Since Vault CLI currently only uses BasicUi,
|
||||
// which writes to standard output, os.Stdout is used here to
|
||||
// directly print the message. If mitchellh/cli exposes method
|
||||
// to print without CR, this check needs to be removed.
|
||||
if reflect.TypeOf(c.Ui).String() == "*cli.BasicUi" {
|
||||
fmt.Fprintf(os.Stdout, val.(string))
|
||||
} else {
|
||||
c.Ui.Output(val.(string))
|
||||
}
|
||||
return 0
|
||||
} else {
|
||||
c.Ui.Error(fmt.Sprintf(
|
||||
|
|
Loading…
Reference in New Issue