Skip to content

Commit

Permalink
Merge pull request #2831 from openziti/add-command-tree
Browse files Browse the repository at this point in the history
Add command-tree cmd to allow comparing CLI layouts
  • Loading branch information
plorenz authored Feb 25, 2025
2 parents bb6bde2 + 792daf9 commit 6c70bf2
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion ziti/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ func NewCmdRoot(in io.Reader, out, err io.Writer, cmd *cobra.Command) *cobra.Com
cmd.AddCommand(common.NewVersionCmd())

cmd.AddCommand(gendoc.NewGendocCmd(cmd))
cmd.AddCommand(newCommandTreeCmd())

return cmd
}

Expand Down Expand Up @@ -229,6 +231,32 @@ func NewRootCommand(in io.Reader, out, err io.Writer) *cobra.Command {
'ziti' is a CLI for working with a Ziti deployment.
`}
NewCmdRoot(in, out, err, ret)

return ret
}

func newCommandTreeCmd() *cobra.Command {
result := &cobra.Command{
Use: "command-tree",
Short: "export the tree of ziti sub-commands",
RunE: func(cmd *cobra.Command, args []string) error {
printCommandAndChildren(cmd.Root(), 0)
return nil
},
}
result.Hidden = true
return result
}

func printCommandAndChildren(cmd *cobra.Command, indent int) {
for i := 0; i < indent; i++ {
fmt.Print(" ")
}
hidden := ""
if cmd.Hidden {
hidden = " (hidden)"
}
fmt.Printf("%s %s\n", cmd.Name(), hidden)
for _, child := range cmd.Commands() {
printCommandAndChildren(child, indent+1)
}
}

0 comments on commit 6c70bf2

Please sign in to comment.