aboutsummaryrefslogblamecommitdiffstats
path: root/commands/commands.go
blob: f06d1ce8769642abab31f4c9485194cc0a8b2051 (plain) (tree)
1
2
3
4
5
6
7
8
9


                
             
                                

 
                     
 
                                                           

                     
                                        
 
                                     





                                     


                                                       
 






                                        
                 
         
 

                             
         
 
                  

 











                                                                                        
 
package commands

import (
	"fmt"
	"github.com/spf13/cobra"
)

var commandsDesc bool

func runCommands(cmd *cobra.Command, args []string) error {
	first := true

	allCmds := cmd.Root().Commands()

	for _, cmd := range allCmds {
		if !first {
			fmt.Println()
		}

		first = false

		if commandsDesc {
			fmt.Printf("# %s\n", cmd.Short)
		}

		fmt.Printf("%s %s",
			rootCommandName,
			cmd.Use,
		)

		if commandsDesc {
			fmt.Println()
		}
	}

	if !commandsDesc {
		fmt.Println()
	}

	return nil
}

var commandsCmd = &cobra.Command{
	Use:   "commands [<option>...]",
	Short: "Display available commands",
	RunE:  runCommands,
}

func init() {
	rootCmd.AddCommand(commandsCmd)

	commandsCmd.Flags().BoolVarP(&commandsDesc, "pretty", "p", false,
		"Output the command description as well as Markdown compatible comment",
	)
}