Skip to content

Improve exit status section #25

@codesections

Description

@codesections

As noted in the comments, the exit_status section is currently hard-coded, but should be revised to accept arguments. Specifically, the exit status section will currently always be:

EXIT STATUS
        0      Successful program execution.

        1      Unsuccessful program execution.

        101    The program panicked.

Looking at a variety of man pages, I've noticed that not all of them have an "exit status" section (including some that I trust to be good, including git, bash, zsh, and rg. Thus, I think that we should make the exit status section optional.

Of course, as noted in the comment, we should make it possible to pass app-specific exit codes. However, it seems like the current implementation (0, 1, and 101) will be a very common default, so it would be nice if we keep that as fairly easy behavior.

Given all of the above, I propose the following API

.exit_status(ExitStatus::default())

produces current behavior

.exit_status(ExitStatus::default_plus([(1, "invalid input"), (3, "could not read file")])

Produces an exit status section with 0 and 101 as defaults plus whatever custom codes and messages the user supplies in an vec of tuples.

.exit_status(ExitStatus::custom([(0, "success")]))

Produces a fully custom exit status section with only the user-supplied codes/messages.

I'm happy to implement this API; please let me know if you think we should go in a different direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions