Пример #1
0
func commandsCmd(c *commander.Command, args []string) error {
	var listCmds func(c *commander.Command)
	listCmds = func(c *commander.Command) {
		pOut("%s\n", c.FullSpacedName())
		for _, sc := range c.Subcommands {
			listCmds(sc)
		}
	}

	listCmds(c.Parent)
	return nil
}
Пример #2
0
func commandsHelpCmd(c *commander.Command, args []string) error {
	pOut(referenceHeaderMsg)
	pOut("Generated on %s.\n\n", time.Now().UTC().Format("2006-01-02"))

	var printCmds func(*commander.Command, int)
	printCmds = func(c *commander.Command, level int) {
		pOut("%s ", strings.Repeat("#", level))
		pOut("%s\n\n", c.FullSpacedName())
		pOut("```\n")
		pOut("%s\n", c.Long)
		pOut("```\n\n")

		for _, sc := range c.Subcommands {
			printCmds(sc, level+1)
		}
	}

	printCmds(c.Parent.Parent, 1)
	return nil
}