Skip to content

Commit

Permalink
topology command: open svg graph in the user’s preferred application
Browse files Browse the repository at this point in the history
Signed-off-by: Eguzki Astiz Lezaun <[email protected]>
  • Loading branch information
eguzki committed Dec 19, 2024
1 parent fd21d07 commit 9eb4601
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package cmd

import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"strings"

"github.com/goccy/go-graphviz"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

0 comments on commit 9eb4601

Please sign in to comment.