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

Exiting from pre_run hooks #13

Open
devnote-dev opened this issue Dec 10, 2023 · 1 comment
Open

Exiting from pre_run hooks #13

devnote-dev opened this issue Dec 10, 2023 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Comments

@devnote-dev
Copy link
Owner

For pre_run hook methods, there is the option to stop command execution to the main run method if the value returned is false. However, there are no checks in place to determine the actual exit code for this, the Executor simply returns which results in a 0 exit code:

begin
res = resolved_command.pre_run executed.parsed_arguments, executed.parsed_options
return unless res.nil? || res

This is obviously not ideal and even misleading for people designing applications that rely on the exit code for debugging or informational purposes. There are already ways to get around this, for example, raising a specific exception that gets funneled to the on_error hook method which then terminates the program with the appropriate exit code. But I think there should be a better way of doing this, even if it's just a shorthand method built into the Command class.

@devnote-dev devnote-dev added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Dec 10, 2023
@devnote-dev
Copy link
Owner Author

A workaround has been implemented in 86caeef and 40e3fe2 that makes use of exception funneling as previously mentioned, meaning that the on_error hook method has been changed to accommodate for it.

While this solution works, I'm contemplating the need for such verbosity/control: if the pre_run hook method were bound to the same rules as the run and post_run hook methods—that is, not having special functionality based on the return type—then it eliminates the need for all of this and thus resolves the initial issue. 🤔

@devnote-dev devnote-dev added the question Further information is requested label Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant