|
9 | 9 | "os"
|
10 | 10 | "strings"
|
11 | 11 |
|
12 |
| - "github.com/drone/drone-yaml/yaml" |
13 |
| - "github.com/drone/drone-yaml/yaml/pretty" |
14 | 12 | "github.com/fatih/color"
|
| 13 | + "github.com/ghodss/yaml" |
15 | 14 | "github.com/google/go-jsonnet"
|
16 | 15 | "github.com/urfave/cli"
|
17 | 16 | )
|
@@ -42,8 +41,9 @@ var Command = cli.Command{
|
42 | 41 | Usage: "Write output as a YAML stream.",
|
43 | 42 | },
|
44 | 43 | cli.BoolFlag{
|
45 |
| - Name: "format", |
46 |
| - Usage: "Write output as formatted YAML", |
| 44 | + Name: "format", |
| 45 | + Hidden: true, |
| 46 | + Usage: "Write output as formatted YAML", |
47 | 47 | },
|
48 | 48 | cli.BoolFlag{
|
49 | 49 | Name: "stdout",
|
@@ -97,31 +97,27 @@ func generate(c *cli.Context) error {
|
97 | 97 | return err
|
98 | 98 | }
|
99 | 99 | for _, doc := range docs {
|
| 100 | + formatted, yErr := yaml.JSONToYAML([]byte(doc)) |
| 101 | + if yErr != nil { |
| 102 | + return fmt.Errorf("failed to convert to YAML: %v", yErr) |
| 103 | + } |
100 | 104 | buf.WriteString("---")
|
101 | 105 | buf.WriteString("\n")
|
102 |
| - buf.WriteString(doc) |
| 106 | + buf.Write(formatted) |
103 | 107 | }
|
104 | 108 | } else {
|
105 | 109 | result, err := vm.EvaluateSnippet(source, string(data))
|
106 | 110 | if err != nil {
|
107 | 111 | return err
|
108 | 112 | }
|
109 |
| - buf.WriteString(result) |
110 |
| - } |
111 |
| - |
112 |
| - // enable yaml formatting with --format |
113 |
| - if c.Bool("format") { |
114 |
| - manifest, err := yaml.Parse(buf) |
115 |
| - if err != nil { |
116 |
| - return err |
| 113 | + formatted, yErr := yaml.JSONToYAML([]byte(result)) |
| 114 | + if yErr != nil { |
| 115 | + return fmt.Errorf("failed to convert to YAML: %v", yErr) |
117 | 116 | }
|
118 |
| - buf.Reset() |
119 |
| - pretty.Print(buf, manifest) |
| 117 | + buf.Write(formatted) |
120 | 118 | }
|
121 | 119 |
|
122 |
| - // the user can optionally write the yaml to stdout. This |
123 |
| - // is useful for debugging purposes without mutating an |
124 |
| - // existing file. |
| 120 | + // the user can optionally write the yaml to stdout. This is useful for debugging purposes without mutating an existing file. |
125 | 121 | if c.Bool("stdout") {
|
126 | 122 | io.Copy(os.Stdout, buf)
|
127 | 123 | return nil
|
|
0 commit comments