Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify exit codes in the --help text #1724

Open
tobysmith568 opened this issue Jan 3, 2025 · 1 comment
Open

Specify exit codes in the --help text #1724

tobysmith568 opened this issue Jan 3, 2025 · 1 comment

Comments

@tobysmith568
Copy link

Is your feature request related to a problem? Please describe.

I would like to have a way to specify expected exit codes to be documented in the --help output, so that users know what codes to expect.

Describe the solution you'd like

I suggest a method on the ICommandConfigurator interface like so for documenting exit codes:

add.AddCommand<CreateFileCommand>("create")
   .WithDescription(CreateFileDescription)
   .WithExitCode(0, "The file is created successfully")
   .WithExitCode(1, "The file could not be created because it failed validation")
   .WithExitCode(2, "Network error")
   .WithExitCode(3, "Server error")

Describe alternatives you've considered

I currently add a block of text to my descriptions like so:

private const string CreateFileDescription =
    """    
    Creates a new file
    
    [yellow]EXIT CODES:[/]
        0 The file is created successfully
        1 The file could not be created because it failed validation
        2 Network error
        3 Server error
    """;
add.AddCommand<CreateFileCommand>("create")
   .WithDescription(CreateFileDescription)

Which fits in quite nicely

image

However, the proposed solution above would mean the exit codes wouldn't need to appear between the description and the usages. I'd suggest the exit codes should appear last, after the options - but I'm open to thoughts. It also means that the formatting would be more standardised.

Additional context

Let me know if this is something you'd be open to receiving a PR for!
Thanks


Please upvote 👍 this issue if you are interested in it.

@FrankRay78
Copy link
Contributor

Well now, isn't this an interesting idea @tobysmith568

Out of interest, do you know of other CLI applications that do this? I'm interested if this is a 'standard' thing eg. POSIX, GNU, defacto, and if so, to see examples of it in the wild,

But if not, that's cool too, it will perhaps need more in-depth consideration as to standardization.

I've looked here https://clig.dev/ and it's very quiet in terms of return code handling, apart from:

"Return zero exit code on success, non-zero on failure. Exit codes are how scripts determine whether a program succeeded or failed, so you should report this correctly. Map the non-zero exit codes to the most important failure modes."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo 🕑
Development

No branches or pull requests

2 participants