11# Generate diagrams for multiple environments in different formats and styles 
2- test-diagram  y = " ": 
3-   @ mkdir -p test-diagram
2+ test-diagram  vlab_workdir = " "  y = " ": 
3+   @ if  [ -n " {{ vlab_workdir}}  "  ]; then mkdir -p test-diagram/ live; fi
4+   @ mkdir -p test-diagram/ default test-diagram/ 3 spine test-diagram/ mesh test-diagram/ 4 mclag2orphan test-diagram/ collapsed-core
45  @ echo " ==============================================="
56  @ echo " Diagram generation test - various topologies, formats, and styles"
7+   @ if  [ -n " {{ vlab_workdir}}  "  ]; then echo " Live diagrams from vlab workdir: {{ vlab_workdir}}  " ; fi
68  @ echo " ==============================================="
79
810  # Check if a VLAB is actually running 
9-   @ echo " === Checking for running VLAB ==="
10-   @ VLAB_PIDS=$(pgrep -f " [h]hfab vlab up"  2 >/ dev/ null ||  echo " " ); \
11-   if  [ -n " $VLAB_PIDS"  ] &&  [ -f " vlab/kubeconfig"  ]; then \
12-     echo " === Detected running VLAB, generating live diagrams ===" ; \
13-     bin/ hhfab diagram --format drawio --style  default --live --output test-diagram/ live-default.drawio ||  echo " Failed to generate live DrawIO diagram" ; \
14-     bin/ hhfab diagram --format drawio --style  cisco --live --output test-diagram/ live-cisco.drawio ||  echo " Failed to generate live DrawIO cisco diagram" ; \
15-     bin/ hhfab diagram --format drawio --style  hedgehog --live --output test-diagram/ live-hedgehog.drawio ||  echo " Failed to generate live DrawIO hedgehog diagram" ; \
16-     bin/ hhfab diagram --format dot --live --output test-diagram/ live.dot ||  echo " Failed to generate live DOT diagram" ; \
17-     if  command -v dot >/ dev/ null 2 >&1  &&  [ -f " test-diagram/live.dot"  ]; then \
18-       dot -Tsvg test-diagram/ live-dot.dot -o test-diagram/ live.dot.svg; \
19-     fi; \
20-     bin/ hhfab diagram --format mermaid --live --output test-diagram/ live-mermaid.mermaid ||  echo " Failed to generate live Mermaid diagram" ; \
21-     if  [ -f " test-diagram/live.mermaid"  ]; then \
22-       echo ' # Live Network Diagram'  > test-diagram/ live.mermaid.md; \
23-       echo ' ```mermaid'  >> test-diagram/ live.mermaid.md; \
24-       cat test-diagram/ live.mermaid >> test-diagram/ live.mermaid.md; \
25-       echo ' ```'  >> test-diagram/ live.mermaid.md; \
11+   @ if  [ -n " {{ vlab_workdir}}  "  ]; then \
12+     echo " === Checking for running VLAB ===" ; \
13+     VLAB_PIDS=$(pgrep -f " [h]hfab vlab up"  2 >/ dev/ null ||  echo " " ); \
14+     if  [ -n " $VLAB_PIDS"  ] &&  [ -f " {{ vlab_workdir}}  /vlab/kubeconfig"  ]; then \
15+       echo " === Detected running VLAB in {{ vlab_workdir}}  , generating live diagrams ===" ; \
16+       HHFAB_CMD=" hhfab" ; \
17+       if  [ -x " {{ vlab_workdir}}  /hhfab"  ]; then \
18+         echo " Using local hhfab from {{ vlab_workdir}}  " ; \
19+         HHFAB_CMD=" ./hhfab" ; \
20+       else  \
21+         echo " Using system hhfab (ensure it's up to date for live diagram support)" ; \
22+       fi; \
23+       LIVE_OUTPUT_DIR=" $(pwd)/test-diagram/live" ; \
24+       mkdir -p " $LIVE_OUTPUT_DIR" ; \
25+       cd {{ vlab_workdir}}   &&  $HHFAB_CMD diagram --format drawio --style  default --live --output " $LIVE_OUTPUT_DIR/default.drawio"  ||  echo " Failed to generate live DrawIO diagram" ; \
26+       cd {{ vlab_workdir}}   &&  $HHFAB_CMD diagram --format drawio --style  cisco --live --output " $LIVE_OUTPUT_DIR/cisco.drawio"  ||  echo " Failed to generate live DrawIO cisco diagram" ; \
27+       cd {{ vlab_workdir}}   &&  $HHFAB_CMD diagram --format drawio --style  hedgehog --live --output " $LIVE_OUTPUT_DIR/hedgehog.drawio"  ||  echo " Failed to generate live DrawIO hedgehog diagram" ; \
28+       cd {{ vlab_workdir}}   &&  $HHFAB_CMD diagram --format dot --live --output " $LIVE_OUTPUT_DIR/live.dot"  ||  echo " Failed to generate live DOT diagram" ; \
29+       cd {{ vlab_workdir}}   &&  $HHFAB_CMD diagram --format mermaid --live --output " $LIVE_OUTPUT_DIR/live.mermaid"  ||  echo " Failed to generate live Mermaid diagram" ; \
30+     elif [ -n " $VLAB_PIDS"  ]; then \
31+       echo " Found running VLAB process but no kubeconfig in {{ vlab_workdir}}  , skipping live diagrams" ; \
32+     elif [ -f " {{ vlab_workdir}}  /vlab/kubeconfig"  ]; then \
33+       echo " Found kubeconfig in {{ vlab_workdir}}   but no running VLAB process, skipping live diagrams" ; \
34+     else  \
35+       echo " No running VLAB detected, skipping live diagrams" ; \
2636    fi; \
2737  else  \
28-     echo " No running VLAB detected , skipping live diagrams" ; \
38+     echo " ===  No vlab_workdir specified , skipping live diagrams === " ; \
2939  fi
3040
3141  # Skip prompt if -y flag is provided 
3242  @ if  [ " {{ y}}  "  = " -y"  ]; then \
3343    true ; \
3444  else  \
35-     echo -n " This will generate diagrams from multiple environments. Continue? [y/N] "  &&  read  ans &&  [ " $ans"  = " y"  -o " $ans"  = " Y"  ]; \
45+     echo " WARNING: This will run 'hhfab init' multiple times in the current directory," ; \
46+     echo " which will overwrite any existing hhfab configuration and VLAB setup." ; \
47+     echo -n " Continue? [y/N] "  &&  read  ans &&  [ " $ans"  = " y"  -o " $ans"  = " Y"  ]; \
3648  fi
3749
3850  @ echo " === Generating diagrams for default VLAB topology ==="
3951  bin/ hhfab init -f --dev --gw
4052  bin/ hhfab vlab gen
4153
4254  # Generate all formats and styles for default topology 
43-   bin/ hhfab diagram --format drawio --style  default --output test-diagram/ default- default.drawio
44-   bin/ hhfab diagram --format drawio --style  cisco --output test-diagram/ default- cisco.drawio
45-   bin/ hhfab diagram --format drawio --style  hedgehog --output test-diagram/ default- hedgehog.drawio
46-   bin/ hhfab diagram --format dot --output test-diagram/ default.dot
47-   bin/ hhfab diagram --format mermaid --output test-diagram/ default.mermaid
55+   bin/ hhfab diagram --format drawio --style  default --output test-diagram/ default/ default.drawio
56+   bin/ hhfab diagram --format drawio --style  cisco --output test-diagram/ default/ cisco.drawio
57+   bin/ hhfab diagram --format drawio --style  hedgehog --output test-diagram/ default/ hedgehog.drawio
58+   bin/ hhfab diagram --format dot --output test-diagram/ default/ default .dot
59+   bin/ hhfab diagram --format mermaid --output test-diagram/ default/ default .mermaid
4860
4961  @ echo " === Generating diagrams for variant 3-spine topology ==="
5062  bin/ hhfab vlab gen --spines-count 3  --mclag-leafs-count 2  --orphan-leafs-count 1  --eslag-leaf-groups 2 
5163
5264  # Generate all formats and styles for 3-spine topology 
53-   bin/ hhfab diagram --format drawio --style  default --output test-diagram/ 3 spine- default.drawio
54-   bin/ hhfab diagram --format drawio --style  cisco --output test-diagram/ 3 spine- cisco.drawio
55-   bin/ hhfab diagram --format drawio --style  hedgehog --output test-diagram/ 3 spine- hedgehog.drawio
56-   bin/ hhfab diagram --format dot --output test-diagram/ 3 spine.dot
57-   bin/ hhfab diagram --format mermaid --output test-diagram/ 3 spine.mermaid
65+   bin/ hhfab diagram --format drawio --style  default --output test-diagram/ 3 spine/ default.drawio
66+   bin/ hhfab diagram --format drawio --style  cisco --output test-diagram/ 3 spine/ cisco.drawio
67+   bin/ hhfab diagram --format drawio --style  hedgehog --output test-diagram/ 3 spine/ hedgehog.drawio
68+   bin/ hhfab diagram --format dot --output test-diagram/ 3 spine/ 3 spine .dot
69+   bin/ hhfab diagram --format mermaid --output test-diagram/ 3 spine/ 3 spine .mermaid
5870
5971  @ echo " === Generating diagrams for 4-mclag-2-orphan topology ==="
6072  bin/ hhfab vlab gen --mclag-leafs-count 4  --orphan-leafs-count 2 
6173
6274  # Generate all formats and styles for 4-mclag-2-orphan topology 
63-   bin/ hhfab diagram --format drawio --style  default --output test-diagram/ 4 mclag2orphan- default.drawio
64-   bin/ hhfab diagram --format drawio --style  cisco --output test-diagram/ 4 mclag2orphan- cisco.drawio
65-   bin/ hhfab diagram --format drawio --style  hedgehog --output test-diagram/ 4 mclag2orphan- hedgehog.drawio
66-   bin/ hhfab diagram --format dot --output test-diagram/ 4 mclag2orphan.dot
67-   bin/ hhfab diagram --format mermaid --output test-diagram/ 4 mclag2orphan.mermaid
75+   bin/ hhfab diagram --format drawio --style  default --output test-diagram/ 4 mclag2orphan/ default.drawio
76+   bin/ hhfab diagram --format drawio --style  cisco --output test-diagram/ 4 mclag2orphan/ cisco.drawio
77+   bin/ hhfab diagram --format drawio --style  hedgehog --output test-diagram/ 4 mclag2orphan/ hedgehog.drawio
78+   bin/ hhfab diagram --format dot --output test-diagram/ 4 mclag2orphan/ 4 mclag2orphan .dot
79+   bin/ hhfab diagram --format mermaid --output test-diagram/ 4 mclag2orphan/ 4 mclag2orphan .mermaid
6880
6981  @ echo " === Generating diagrams for mesh topology ==="
7082  bin/ hhfab vlab gen --mesh-links-count 2 
7183
72-   # Generate all formats and styles for 4-mclag-2-orphan  topology 
73-   bin/ hhfab diagram --format drawio --style  default --output test-diagram/ mesh- default.drawio
74-   bin/ hhfab diagram --format drawio --style  cisco --output test-diagram/ mesh- cisco.drawio
75-   bin/ hhfab diagram --format drawio --style  hedgehog --output test-diagram/ mesh- hedgehog.drawio
76-   bin/ hhfab diagram --format dot --output test-diagram/ mesh.dot
77-   bin/ hhfab diagram --format mermaid --output test-diagram/ mesh.mermaid
84+   # Generate all formats and styles for mesh  topology 
85+   bin/ hhfab diagram --format drawio --style  default --output test-diagram/ mesh/ default.drawio
86+   bin/ hhfab diagram --format drawio --style  cisco --output test-diagram/ mesh/ cisco.drawio
87+   bin/ hhfab diagram --format drawio --style  hedgehog --output test-diagram/ mesh/ hedgehog.drawio
88+   bin/ hhfab diagram --format dot --output test-diagram/ mesh/ mesh .dot
89+   bin/ hhfab diagram --format mermaid --output test-diagram/ mesh/ mesh .mermaid
7890
7991  @ echo " === Generating diagrams for collapsed core topology ==="
8092  bin/ hhfab init -f --dev --fabric-mode collapsed-core
8193  bin/ hhfab vlab gen
8294
8395  # Generate all formats and styles for collapsed core topology 
84-   bin/ hhfab diagram --format drawio --style  default --output test-diagram/ collapsed-core- default.drawio
85-   bin/ hhfab diagram --format drawio --style  cisco --output test-diagram/ collapsed-core- cisco.drawio
86-   bin/ hhfab diagram --format drawio --style  hedgehog --output test-diagram/ collapsed-corehedgehog .drawio
87-   bin/ hhfab diagram --format dot --output test-diagram/ collapsed-core.dot
88-   bin/ hhfab diagram --format mermaid --output test-diagram/ collapsed-core.mermaid
96+   bin/ hhfab diagram --format drawio --style  default --output test-diagram/ collapsed-core/ default.drawio
97+   bin/ hhfab diagram --format drawio --style  cisco --output test-diagram/ collapsed-core/ cisco.drawio
98+   bin/ hhfab diagram --format drawio --style  hedgehog --output test-diagram/ collapsed-core / hedgehog .drawio
99+   bin/ hhfab diagram --format dot --output test-diagram/ collapsed-core/ collapsed-core .dot
100+   bin/ hhfab diagram --format mermaid --output test-diagram/ collapsed-core/ collapsed-core .mermaid
89101
90102  # Convert DRAWIO files to SVG 
91-   @ echo " === Converting DRAWIO files to SVG if GraphViz is installed  ==="
103+   @ echo " === Converting DRAWIO files to SVG ==="
92104  @ if  command -v drawio >/ dev/ null 2 >&1 ; then \
93-     for DRAWIO_FILE in  test-diagram/ *.drawio; do \
105+     find  test-diagram -name  " *.drawio"  -type f | while  read  DRAWIO_FILE ; do \
94106      SVG_FILE=" ${DRAWIO_FILE}.svg" ; \
95107      echo " Converting $DRAWIO_FILE to $SVG_FILE" ; \
96108      drawio --export --format svg \
97109             - -output " $SVG_FILE"  \
98110             " $DRAWIO_FILE" ; \
99111    done; \
100112  else  \
101-     echo " Drawio  not installed , skipping SVG conversion" ; \
113+     echo " WARNING: DrawIO CLI  not available , skipping .drawio to  SVG conversion" ; \
102114  fi
103115
104116  # Convert DOT files to SVG 
105-   @ echo " === Converting DOT files to SVG if GraphViz is installed  ==="
117+   @ echo " === Converting DOT files to SVG ==="
106118  @ if  command -v dot >/ dev/ null 2 >&1 ; then \
107-     for DOT_FILE in  test-diagram/ *.dot; do \
119+     find  test-diagram -name  " *.dot"  -type f | while  read  DOT_FILE ; do \
108120      SVG_FILE=" ${DOT_FILE}.svg" ; \
109121      echo " Converting $DOT_FILE to $SVG_FILE" ; \
110122      dot -Tsvg " $DOT_FILE"  -o " $SVG_FILE" ; \
111123    done; \
112124  else  \
113-     echo " GraphViz dot  not installed , skipping SVG conversion" ; \
125+     echo " WARNING:  GraphViz not available , skipping .dot to  SVG conversion" ; \
114126  fi
115127
116-   # Create markdown files with embedded mermaid diagrams 
117-   @ echo " === Creating Markdown files with embedded Mermaid diagrams ==="
118-   @ for MERMAID_FILE in test-diagram/ *.mermaid; do \
119-     MD_FILE=" ${MERMAID_FILE%.mermaid}.md" ; \
120-     BASE_NAME=$(basename " $MERMAID_FILE"  -mermaid.mermaid); \
121-     echo " Creating $MD_FILE" ; \
122-     echo " # $BASE_NAME Network Diagram"  > " $MD_FILE" ; \
123-     echo ' ```mermaid'  >> " $MD_FILE" ; \
124-     cat " $MERMAID_FILE"  >> " $MD_FILE" ; \
125-     echo ' ```'  >> " $MD_FILE" ; \
126-   done
127- 
128128  # Convert Mermaid files to SVG 
129129  @ echo " === Converting Mermaid files to SVG ==="
130130  @ if  command -v mmdc >/ dev/ null 2 >&1 ; then \
131-     for MERMAID_FILE in test-diagram/ *.mermaid; do \
132-       if  [ -f " $MERMAID_FILE"  ]; then \
133-         SVG_FILE=" ${MERMAID_FILE%.mermaid}.mermaid.svg" ; \
134-         echo " Converting $MERMAID_FILE to $SVG_FILE" ; \
135-         mmdc -i " $MERMAID_FILE"  -o " $SVG_FILE"  -t default -b white; \
136-       fi; \
131+     find test-diagram -name " *.mermaid"  -type f | while read  MERMAID_FILE; do \
132+       SVG_FILE=" ${MERMAID_FILE%.mermaid}.mermaid.svg" ; \
133+       echo " Converting $MERMAID_FILE to $SVG_FILE" ; \
134+       mmdc -i " $MERMAID_FILE"  -o " $SVG_FILE"  -t default -b white; \
137135    done; \
138136  else  \
139-     echo " Mermaid CLI not installed. Install with: npm install -g @mermaid-js/mermaid-cli " ; \
137+     echo " WARNING:  Mermaid CLI not available, skipping .mermaid to SVG conversion " ; \
140138  fi
141139
142140  @ echo " "
143141  @ echo " All diagrams generated in test-diagram/ directory"
144-   @ ls -la test-diagram/ 
145-   @ echo " "
146-   @ echo " Summary of generated files:"
147-   @ echo " - Default VLAB topology: default-*"
148-   @ echo " - 3-spine VLAB topology: 3spine-*"
149-   @ echo " - 4-mclag-2-orphan topology: 4mclag2orphan-*"
150-   @ echo " - Collapsed core topology: collapsed-core-*"
151-   @ echo " - Live diagrams (if VLAB running): live-*"
142+   @ find test-diagram -type f | sort
152143  @ echo " "
153-   @ echo " For each topology, these formats are available:"
154-   @ echo " - DrawIO: *-drawio-{default,cisco,hedgehog}.drawio"
155-   @ echo " - DOT: *-dot.dot (and SVG if GraphViz was installed)"
156-   @ echo " - Mermaid: *-mermaid.mermaid (and embedded in markdown *.md)"
144+   @ echo " Summary of generated topology directories:"
145+   @ echo " - Default VLAB topology: test-diagram/default/"
146+   @ echo " - 3-spine VLAB topology: test-diagram/3spine/"
147+   @ echo " - 4-mclag-2-orphan topology: test-diagram/4mclag2orphan/"
148+   @ echo " - Mesh topology: test-diagram/mesh/"
149+   @ echo " - Collapsed core topology: test-diagram/collapsed-core/"
150+   @ if  [ -n " {{ vlab_workdir}}  "  ]; then echo " - Live diagrams (if VLAB in {{ vlab_workdir}}  ): test-diagram/live/" ; fi
157151
158152  @ just _create-html
159153
@@ -164,6 +158,11 @@ test-diagram y="":
164158  @ echo "    firefox test-diagram/diagram-viewer.html"
165159  @ echo "    # or"
166160  @ echo "    xdg-open test-diagram/diagram-viewer.html"
161+   @ echo " "
162+   @ echo " Usage examples:"
163+   @ echo "    just test-diagram                                    # No live diagrams, interactive"
164+   @ echo "    just test-diagram \"\"  \" -y\"                            # No live diagrams, auto-confirm"
165+   @ echo "    just test-diagram \" /path/to/vlab\"  \" -y\"               # With live diagrams, auto-confirm"
167166
168167# Clean up all generated diagrams 
169168clean -diagram:
0 commit comments