| 294 | } |
| 295 | |
| 296 | func (t *treeCmd) printTreeWithPrefix(info *portInfo, prefix string, isLast bool) { |
| 297 | var branch string |
| 298 | if info.depth == 0 { |
| 299 | branch = "" |
| 300 | } else if isLast { |
| 301 | branch = "└── " |
| 302 | } else { |
| 303 | branch = "├── " |
| 304 | } |
| 305 | |
| 306 | // Compose the line to print. |
| 307 | line := branch + info.nameVersion |
| 308 | if info.devDep { |
| 309 | line += " -- [dev]" |
| 310 | } |
| 311 | color.Println(color.Hint, prefix+line) |
| 312 | |
| 313 | // Prepare the prefix for the next level. |
| 314 | var nextPrefix string |
| 315 | if info.depth == 0 { |
| 316 | nextPrefix = "" |
| 317 | } else if isLast { |
| 318 | nextPrefix = prefix + " " // No vertical line if this is the last child. |
| 319 | } else { |
| 320 | nextPrefix = prefix + "│ " // Keep vertical line for siblings. |
| 321 | } |
| 322 | |
| 323 | // Merge normal and dev dependencies (if not hidden). |
| 324 | children := info.depedencies |
| 325 | if !t.hideDevDep { |
| 326 | children = append(children, info.devDependencies...) |
| 327 | } |
| 328 | |
| 329 | // Recursively print children |
| 330 | for i, child := range children { |
| 331 | t.printTreeWithPrefix(child, nextPrefix, i == len(children)-1) |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | func (t *treeCmd) completion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 336 | var suggestions []string |