forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_json2dot.go
66 lines (52 loc) · 1.31 KB
/
debug_json2dot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package command
import (
"fmt"
"os"
"strings"
"github.com/hashicorp/terraform/dag"
"github.com/mitchellh/cli"
)
// DebugJSON2DotCommand is a Command implementation that translates a json
// graph debug log to Dot format.
type DebugJSON2DotCommand struct {
Meta
}
func (c *DebugJSON2DotCommand) Run(args []string) int {
args, err := c.Meta.process(args, true)
if err != nil {
return 1
}
cmdFlags := c.Meta.flagSet("debug json2dot")
if err := cmdFlags.Parse(args); err != nil {
return cli.RunResultHelp
}
fileName := cmdFlags.Arg(0)
if fileName == "" {
return cli.RunResultHelp
}
f, err := os.Open(fileName)
if err != nil {
c.Ui.Error(fmt.Sprintf(errInvalidLog, err))
return cli.RunResultHelp
}
dot, err := dag.JSON2Dot(f)
if err != nil {
c.Ui.Error(fmt.Sprintf(errInvalidLog, err))
return cli.RunResultHelp
}
c.Ui.Output(string(dot))
return 0
}
func (c *DebugJSON2DotCommand) Help() string {
helpText := `
Usage: terraform debug json2dot input.json
Translate a graph debug file to dot format.
This command takes a single json graph log file and converts it to a single
dot graph written to stdout.
`
return strings.TrimSpace(helpText)
}
func (c *DebugJSON2DotCommand) Synopsis() string {
return "Convert json graph log to dot"
}
const errInvalidLog = `Error parsing log file: %[1]s`