aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/util/cmd.go
blob: ae79aa071c5082dd4456ee9f1d361e1c6270d305 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package util

import (
	"bytes"

	"github.com/spf13/cobra"
)

// ExitCodeError is a specific error that is returned by the command to specify the exit code
type ExitCodeError struct {
	ExitCode int
}

func (e *ExitCodeError) Error() string { return "exit code error" }

// HelpForCobraCmd returns the help string for a given command
// Note that this overwrites the output for the command
func HelpForCobraCmd(cmd *cobra.Command) string {
	f := cmd.HelpFunc()
	buf := bytes.NewBufferString("")
	cmd.SetOut(buf)
	f(cmd, []string{})
	return buf.String()
}