| 348 | } |
| 349 | |
| 350 | func publicCommandSubtree(cmd *cobra.Command) []*cobra.Command { |
| 351 | if cmd == nil { |
| 352 | return nil |
| 353 | } |
| 354 | var commands []*cobra.Command |
| 355 | var walk func(*cobra.Command) |
| 356 | walk = func(current *cobra.Command) { |
| 357 | if !current.Hidden { |
| 358 | commands = append(commands, current) |
| 359 | } |
| 360 | children := append([]*cobra.Command{}, current.Commands()...) |
| 361 | sort.Slice(children, func(i, j int) bool { |
| 362 | return jsonCommandPath(children[i]) < jsonCommandPath(children[j]) |
| 363 | }) |
| 364 | for _, child := range children { |
| 365 | if child.Hidden { |
| 366 | continue |
| 367 | } |
| 368 | walk(child) |
| 369 | } |
| 370 | } |
| 371 | walk(cmd) |
| 372 | return commands |
| 373 | } |
| 374 | |
| 375 | func jsonCommandManifestFor(cmd *cobra.Command) jsonCommandManifest { |
| 376 | cmd.InitDefaultHelpFlag() |