aboutsummaryrefslogblamecommitdiffstats
path: root/commands/commands.go
blob: 51aa4e9a3fe74cbba424566f758ec28f48f0571d (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",
	)
}