Merge pull request #832 from mlafeldt/yaml-ouput

Allow to output secrets in YAML format
This commit is contained in:
Jeff Mitchell
2015-12-11 12:04:41 -05:00
32 changed files with 12339 additions and 4 deletions

View File

@@ -6,7 +6,9 @@ import (
"fmt"
"sort"
"strconv"
"strings"
"github.com/ghodss/yaml"
"github.com/hashicorp/vault/api"
"github.com/mitchellh/cli"
"github.com/ryanuber/columnize"
@@ -16,6 +18,8 @@ func OutputSecret(ui cli.Ui, format string, secret *api.Secret) int {
switch format {
case "json":
return outputFormatJSON(ui, secret)
case "yaml":
return outputFormatYAML(ui, secret)
case "table":
fallthrough
default:
@@ -37,6 +41,18 @@ func outputFormatJSON(ui cli.Ui, s *api.Secret) int {
return 0
}
func outputFormatYAML(ui cli.Ui, s *api.Secret) int {
b, err := yaml.Marshal(s)
if err != nil {
ui.Error(fmt.Sprintf(
"Error formatting secret: %s", err))
return 1
}
ui.Output(strings.TrimSpace(string(b)))
return 0
}
func outputFormatTable(ui cli.Ui, s *api.Secret, whitespace bool) int {
config := columnize.DefaultConfig()
config.Delim = "♨"