Fix pr checks exit code (#9452)
* Enhance with exit code documentation * Add new error message for PR check * Refine gh pr checks: Add exit code 8 * Update EXIT CODES section format in man page generation
This commit is contained in:
parent
255f5301d5
commit
1886fb46ab
4 changed files with 39 additions and 0 deletions
|
|
@ -198,6 +198,15 @@ func manPrintJSONFields(buf *bytes.Buffer, command *cobra.Command) {
|
|||
buf.WriteString("\n")
|
||||
}
|
||||
|
||||
func manPrintExitCodes(buf *bytes.Buffer) {
|
||||
buf.WriteString("# EXIT CODES\n")
|
||||
buf.WriteString("0: Successful execution\n\n")
|
||||
buf.WriteString("1: Error\n\n")
|
||||
buf.WriteString("2: Command canceled\n\n")
|
||||
buf.WriteString("4: Authentication required\n\n")
|
||||
buf.WriteString("NOTE: Specific commands may have additional exit codes. Refer to the command's help for more information.\n\n")
|
||||
}
|
||||
|
||||
func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
|
||||
cmd.InitDefaultHelpCmd()
|
||||
cmd.InitDefaultHelpFlag()
|
||||
|
|
@ -217,6 +226,7 @@ func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
|
|||
manPrintOptions(buf, cmd)
|
||||
manPrintAliases(buf, cmd)
|
||||
manPrintJSONFields(buf, cmd)
|
||||
manPrintExitCodes(buf)
|
||||
if len(cmd.Example) > 0 {
|
||||
buf.WriteString("# EXAMPLE\n")
|
||||
buf.WriteString(fmt.Sprintf("```\n%s\n```\n", cmd.Example))
|
||||
|
|
|
|||
|
|
@ -129,6 +129,31 @@ func TestGenManJSONFields(t *testing.T) {
|
|||
checkStringContains(t, output, "baz")
|
||||
}
|
||||
|
||||
func TestGenManDocExitCodes(t *testing.T) {
|
||||
header := &GenManHeader{
|
||||
Title: "Project",
|
||||
Section: "1",
|
||||
}
|
||||
cmd := &cobra.Command{
|
||||
Use: "test-command",
|
||||
Short: "A test command",
|
||||
Long: "A test command for checking exit codes section",
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
if err := renderMan(cmd, header, buf); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
output := buf.String()
|
||||
|
||||
// Check for the presence of the exit codes section
|
||||
checkStringContains(t, output, ".SH EXIT CODES")
|
||||
checkStringContains(t, output, "0: Successful execution")
|
||||
checkStringContains(t, output, "1: Error")
|
||||
checkStringContains(t, output, "2: Command canceled")
|
||||
checkStringContains(t, output, "4: Authentication required")
|
||||
checkStringContains(t, output, "NOTE: Specific commands may have additional exit codes. Refer to the command's help for more information.")
|
||||
}
|
||||
|
||||
func TestManPrintFlagsHidesShortDeprecated(t *testing.T) {
|
||||
c := &cobra.Command{}
|
||||
c.Flags().StringP("foo", "f", "default", "Foo flag")
|
||||
|
|
|
|||
|
|
@ -66,6 +66,9 @@ func NewCmdChecks(f *cmdutil.Factory, runF func(*ChecksOptions) error) *cobra.Co
|
|||
|
||||
Without an argument, the pull request that belongs to the current branch
|
||||
is selected.
|
||||
|
||||
Additional exit codes:
|
||||
8: Checks pending
|
||||
`),
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
|
|
|||
|
|
@ -182,6 +182,7 @@ func rootHelpFunc(f *cmdutil.Factory, command *cobra.Command, args []string) {
|
|||
helpEntries = append(helpEntries, helpEntry{"LEARN MORE", heredoc.Docf(`
|
||||
Use %[1]sgh <command> <subcommand> --help%[1]s for more information about a command.
|
||||
Read the manual at https://cli.github.com/manual
|
||||
Learn about exit codes using %[1]sgh help exit-codes%[1]s
|
||||
`, "`")})
|
||||
|
||||
out := f.IOStreams.Out
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue