mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-29 10:21:01 -06:00
b8adf10236
Add `terraform debug json2dot` to convert debug log graphs to dot format. This is not meant to be in place of more advanced debug visualization, but may continue to be a useful way to work with the debug output.
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
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 = c.Meta.process(args, true)
|
|
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`
|