diff options
| author | 2023-04-28 01:36:44 +0800 | |
|---|---|---|
| committer | 2023-04-28 01:36:44 +0800 | |
| commit | dd84b9d64fb98746a230cd24233ff50a562c39c9 (patch) | |
| tree | b583261ef00b3afe72ec4d6dacb31e57779a6faf /cli/internal/util/cmd.go | |
| parent | 0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff) | |
| download | HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip | |
Diffstat (limited to 'cli/internal/util/cmd.go')
| -rw-r--r-- | cli/internal/util/cmd.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cli/internal/util/cmd.go b/cli/internal/util/cmd.go new file mode 100644 index 0000000..ae79aa0 --- /dev/null +++ b/cli/internal/util/cmd.go @@ -0,0 +1,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() +} |
