diff --git a/clab/graph.go b/clab/graph.go index f55994bf1..e178778be 100644 --- a/clab/graph.go +++ b/clab/graph.go @@ -273,20 +273,34 @@ func (c *CLab) ServeTopoGraph(tmpl, staticDir, srv string, topoD TopoData) error return http.ListenAndServe(srv, nil) } -func (c *CLab) GenerateDrawioDiagram(version string) error { +func (c *CLab) GenerateDrawioDiagram(version string, additionalFlags []string) error { topoFile := c.TopoPaths.TopologyFilenameBase() - cmd := exec.Command("sudo", "docker", "run", "-v", - fmt.Sprintf("%s:/data", c.TopoPaths.TopologyFileDir()), + cmdArgs := []string{ + "docker", "run", + "-v", fmt.Sprintf("%s:/data", c.TopoPaths.TopologyFileDir()), fmt.Sprintf("ghcr.io/srl-labs/clab-io-draw:%s", version), - "-i", topoFile) + "-i", topoFile, + } + + log.Infof("Generating draw.io diagram with version: %s", version) + + // Process additional flags + for _, flag := range additionalFlags { + parts := strings.Fields(flag) + cmdArgs = append(cmdArgs, parts...) + } + + cmd := exec.Command("sudo", cmdArgs...) out, err := cmd.CombinedOutput() if err != nil { - log.Fatalf("cmd.CombinedOutput() failed with %s\n", err) + log.Errorf("Command execution failed: %v", err) + log.Errorf("Command output: %s", string(out)) + return fmt.Errorf("failed to generate diagram: %w\nOutput: %s", err, string(out)) } - log.Infof("Diagram created. %s", out) + log.Infof("Diagram created successfully. Output: %s", string(out)) return nil } diff --git a/cmd/graph.go b/cmd/graph.go index 3e8f129a0..ba2bf6589 100644 --- a/cmd/graph.go +++ b/cmd/graph.go @@ -33,6 +33,7 @@ var ( mermaidDirection string drawio bool drawioVersion string + drawioArgs []string staticDir string ) @@ -79,7 +80,7 @@ func graphFn(_ *cobra.Command, _ []string) error { } if drawio { - return c.GenerateDrawioDiagram(drawioVersion) + return c.GenerateDrawioDiagram(drawioVersion, drawioArgs) } gtopo := clab.GraphTopo{ @@ -153,6 +154,8 @@ func init() { graphCmd.Flags().BoolVarP(&dot, "dot", "", false, "generate dot file") graphCmd.Flags().BoolVarP(&mermaid, "mermaid", "", false, "print mermaid flowchart to stdout") graphCmd.Flags().StringVarP(&mermaidDirection, "mermaid-direction", "", "TD", "specify direction of mermaid dirgram") + graphCmd.Flags().StringSliceVar(&drawioArgs, "drawio-args", []string{}, + "Additional flags to pass to the drawio diagram generation tool (can be specified multiple times)") graphCmd.Flags().BoolVarP(&drawio, "drawio", "", false, "generate drawio diagram file") graphCmd.Flags().StringVarP(&drawioVersion, "drawio-version", "", "latest", "version of the clab-io-draw container to use for generating drawio diagram file") diff --git a/docs/cmd/graph.md b/docs/cmd/graph.md index 82ec0149b..07aa7c144 100644 --- a/docs/cmd/graph.md +++ b/docs/cmd/graph.md @@ -64,6 +64,12 @@ The `group` property set to the predefined value will automatically auto-align t When `graph` command is called with the `--drawio` flag, containerlab will leverage the [`clab-io-draw`](https://github.com/srl-labs/clab-io-draw) project to generate the drawio file that represents the topology in a graphical form and can be imported into [draw.io](https://draw.io). +You can pass additional arguments to the `clab-io-draw` tool using the `--drawio-args=` flag. For example: + +``` +containerlab graph --drawio --drawio-args="--theme nokia_dark --layout horizontal" -t topo.yaml +``` + ### Mermaid When `graph` is called with the `--mermaid` flag containerlab generates a graph description file in [Mermaid graph format](https://mermaid.js.org/syntax/flowchart.html). Several [Markdown renders](https://mermaid.js.org/ecosystem/integrations-community.html) such as Github, Gitlab, and Notion support rendering embeded mermaid graphs in code blocks. If the results of the render are not satisfying the result can be imported into [draw.io](https://draw.io) and further edited.