-
Notifications
You must be signed in to change notification settings - Fork 9
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
Improve exit status
section
#25
Comments
Should CLIs always document exit codes?
Hmm, I wonder about that. In the case of APIWith the rest of the APIs every item is added individually. That would more or less translate to this: let page = Manual::new("basic")
.exit_status(3, "Invalid config.")
.exit_status(5, "Could not read file.")
.render(); Optional Defaults?Circling back to the question of defaults. I think we're on the same page that we want to have a convenient way to include the defaults, but there's a question if they should be enabled by default. I'm thinking there's two options:
This would roughly translate to two possible APIs: opt-out of defaultsdefaults enabledlet page = Manual::new("basic")
.exit_status(3, "Invalid config.")
.exit_status(5, "Could not read file.")
.render(); defaults disabledlet page = Manual::new("basic")
.no_default_exit_status()
.exit_status(0, "Successful program execution.")
.exit_status(1, "Unsuccessful program execution.")
.exit_status(3, "Invalid config.")
.exit_status(5, "Could not read file.")
.exit_status(101, "Program panicked.")
.render(); opt-in to defaultsdefaults enabledlet page = Manual::new("basic")
.default_exit_status()
.exit_status(3, "Invalid config.")
.exit_status(5, "Could not read file.")
.render(); defaults disabledlet page = Manual::new("basic")
.exit_status(0, "Successful program execution.")
.exit_status(1, "Unsuccessful program execution.")
.exit_status(3, "Invalid config.")
.exit_status(5, "Could not read file.")
.exit_status(101, "Program panicked.")
.render(); I'm not sure what the best option here is. I feel there's arguments for both; I'd be curious to hear which people prefer. |
Hmm, interesting thoughts. One point comes to mind: with most of our methods ( opt-out of defaults let page = Manual::new("basic")
.exit_status(ExitStatus::no_defaults())
.exit_status(
ExitStatus::new(0)
.description("Successful program execution.")
)
.exit_status(
ExitStatus::new(1)
.description("Unsuccessful program execution.")
)
.exit_status(
ExitStatus::new(3)
.description("Invalid config.")
)
.exit_status(
ExitStatus::new(5)
.description("Could not read file")
)
.exit_status(
ExitStatus::new(101).
description("Program panicked.")
)
.render(); or opt-into defaults let page = Manual::new("basic")
.exit_status(ExitStatus::default())
.exit_status(
ExitStatus::new(1)
.description("Unsuccessful program execution.")
)
.exit_status(
ExitStatus::new(3)
.description("Invalid config.")
)
.exit_status(
ExitStatus::new(5)
.description("Could not read file")
)
.render(); Admittedly, this version of the API is slightly more verbose—but I think I'd prefer it a bit based on the consistency with the rest of the API. Plus, it seems like it makes the One related point: In the first API I proposed, I was suggesting that the/a default could preserve the current behavior (giving 0, 1, and 101 exit codes). The API you proposed, on the other hand, had only 0 and 101. If we could have all three as the default, that seems to argue a bit in favor of the opt-in: the most common use-case would just be let page = Manual::new("basic")
.exit_status(ExitStatus::default())
.render(); Of course, the downside of providing more in the default is that more people would need to opt out. |
@codesections originally those APIs didn't take structs either. But because every argument ended up being on
I think that example looks pretty reasonable actually -- I like it a lot! |
We discussed the API proposed here in #30 and I noticed that I don't fully agree with it. The main issue for me is that Here's the API I'd try to offer, with my expectations. This is very similar to what @yoshuawuyts proposed as "opt-in to defaults" above. Emptylet page = Manual::new("basic").render(); This does not output a list of error codes. Just default errorslet page = Manual::new("basic")
.use_default_exit_statuses()
.render(); This renders the three default error codes (with their default description). The basic caselet page = Manual::new("basic")
.exit_status(
ExitStatus::new(5)
.description("Could not read file")
)
.render(); This renders an exit code section with just one error code listed, 5. Defaults and morelet page = Manual::new("basic")
.use_default_exit_statuses()
.exit_status(
ExitStatus::new(5)
.description("Could not read file")
)
.render(); This renders the three default error codes, plus the exit code 5. Overwrite an exit code(optional to implement but would make sense to me to support) let page = Manual::new("basic")
.use_default_exit_statuses()
.exit_status(
ExitStatus::new(5)
.description("Could not read file")
)
.exit_status(
ExitStatus::new(5)
.description("Foobar")
)
.render(); This renders the three default error codes, plus the exit code 5 which has "Foobar" s description. |
I like this API, and agree that it's similar to one of @yoshuawuyts's suggestions above. My only concern with this is that it adds two methods to I was reviewing the clap-rs API to see how they handle it, and it looks like they have a I wonder if we could do the same? If we did that, here's what the API examples from above would look like: (Another advantage of pulling this out into a setting is that we could make this (or any other default) opt-out if we later want to)
|
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: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
, andrg
. 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
produces current behavior
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.
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.
The text was updated successfully, but these errors were encountered: