Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topology command: open svg graph in the user’s preferred application #107

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 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 All @@ -22,13 +25,13 @@ var (
func topologyCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "topology",
Short: "Read kuadrant topology",
Long: "Read kuadrant topology",
Short: "Export and visualize kuadrant topology",
Long: "Export and visualize kuadrant topology",
RunE: runTopology,
}

cmd.Flags().StringVarP(&topologyNS, "namespace", "n", "kuadrant-system", "Topology's namespace")
cmd.Flags().StringVarP(&topologyOutputFile, "output", "o", "(required)", "Output file")
cmd.Flags().StringVarP(&topologyOutputFile, "output", "o", "", "Output file")
err := cmd.MarkFlagRequired("output")
if err != nil {
panic(err)
Expand All @@ -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)
trepel marked this conversation as resolved.
Show resolved Hide resolved
// 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
}
Loading