fix(dep tree): match --format mermaid case-insensitively (#6646)
`bd dep tree --format Mermaid` fell through silently to the plain-text renderer because the mermaid check was a raw string comparison while the json check two lines earlier already folds case. Extract the check into isMermaidTreeFormat and use strings.EqualFold, matching json. Refs #6339 Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
eb691bf128
commit
ce512c3b2b
2 changed files with 29 additions and 1 deletions
|
|
@ -517,6 +517,29 @@ func TestDepTreeFormatFlag(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestDepTreeFormatMermaidCaseInsensitive pins that --format mermaid folds case
|
||||
// the same way the json format check does.
|
||||
func TestDepTreeFormatMermaidCaseInsensitive(t *testing.T) {
|
||||
tests := []struct {
|
||||
format string
|
||||
want bool
|
||||
}{
|
||||
{"mermaid", true},
|
||||
{"Mermaid", true},
|
||||
{"MERMAID", true},
|
||||
{"", false},
|
||||
{"json", false},
|
||||
{"dot", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.format, func(t *testing.T) {
|
||||
if got := isMermaidTreeFormat(tt.format); got != tt.want {
|
||||
t.Errorf("isMermaidTreeFormat(%q) = %v, want %v", tt.format, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetStatusEmoji(t *testing.T) {
|
||||
tests := []struct {
|
||||
status types.Status
|
||||
|
|
|
|||
|
|
@ -80,6 +80,11 @@ func proxiedTreeTarget(ctx context.Context, arg string) (treeTarget, error) {
|
|||
return treeTarget{rootID: rootID, walker: walker, cleanup: func() {}}, nil
|
||||
}
|
||||
|
||||
// isMermaidTreeFormat reports whether --format selects the mermaid renderer.
|
||||
func isMermaidTreeFormat(formatStr string) bool {
|
||||
return strings.EqualFold(formatStr, "mermaid")
|
||||
}
|
||||
|
||||
// runDepTree is the whole of `bd dep tree` on both routes.
|
||||
func runDepTree(cmd *cobra.Command, ctx context.Context, args []string) error {
|
||||
maxDepth, _ := cmd.Flags().GetInt("max-depth")
|
||||
|
|
@ -145,7 +150,7 @@ func runDepTree(cmd *cobra.Command, ctx context.Context, args []string) error {
|
|||
tree := result.Nodes
|
||||
|
||||
// Handle format presets (json handled earlier, near the flag read).
|
||||
if formatStr == "mermaid" {
|
||||
if isMermaidTreeFormat(formatStr) {
|
||||
// The raw argument, not the resolved id: this is only read when the tree
|
||||
// is empty.
|
||||
outputMermaidTree(tree, args[0])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue