git-bug/commands/commands.go

56 lines
825 B
Go
Raw Normal View History

2018-07-12 10:55:13 +03:00
package commands
import (
"fmt"
"github.com/spf13/cobra"
2018-07-12 10:55:13 +03:00
)
var commandsDesc bool
func runCommands(cmd *cobra.Command, args []string) error {
first := true
allCmds := cmd.Root().Commands()
2018-07-16 23:38:52 +03:00
for _, cmd := range allCmds {
if !first {
fmt.Println()
}
first = false
if commandsDesc {
fmt.Printf("# %s\n", cmd.Short)
}
2018-07-16 23:38:52 +03:00
fmt.Printf("%s %s",
rootCommandName,
cmd.Use,
)
if commandsDesc {
fmt.Println()
}
}
if !commandsDesc {
fmt.Println()
}
2018-07-12 10:55:13 +03:00
return nil
2018-07-12 10:55:13 +03:00
}
var commandsCmd = &cobra.Command{
Use: "commands [<option>...]",
Short: "Display available commands",
RunE: runCommands,
}
func init() {
2018-07-20 16:46:14 +03:00
RootCmd.AddCommand(commandsCmd)
commandsCmd.Flags().BoolVarP(&commandsDesc, "pretty", "p", false,
"Output the command description as well as Markdown compatible comment",
)
2018-07-12 10:55:13 +03:00
}