diff --git a/cmd/topology.go b/cmd/topology.go index a9ce689..d68c6b8 100644 --- a/cmd/topology.go +++ b/cmd/topology.go @@ -2,8 +2,11 @@ package cmd import ( "bytes" + "errors" "fmt" "os" + "os/exec" + "strings" "github.com/goccy/go-graphviz" "github.com/spf13/cobra" @@ -37,6 +40,9 @@ func topologyCommand() *cobra.Command { } func runTopology(cmd *cobra.Command, args []string) error { + if !strings.HasSuffix(topologyOutputFile, ".svg") { + return errors.New("output file must have .svg extension") + } ctx := cmd.Context() configuration, err := config.GetConfig() if err != nil { @@ -108,5 +114,16 @@ func runTopology(cmd *cobra.Command, args []string) error { return err } + openCmd := exec.Command("open", topologyOutputFile) + // pipe the commands output to the applications + // standard output + openCmd.Stdout = os.Stdout + + // Run still runs the command and waits for completion + // but the output is instantly piped to Stdout + if err := openCmd.Run(); err != nil { + return err + } + return nil }