-
Notifications
You must be signed in to change notification settings - Fork 116
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
Update hooks example to handle redirection #1195
Conversation
Previously redirection information was lost by the postparsing hooks add_whitespace_hook() and downcase_hook(). This was fine for this simple shell, but sets a bad example for more complicated use cases. To fix this, when parsing the new Statement object, include the `post_command` attribute from the original Statement.
Not necessary for the sake of the example, but might help some curious individuals get a better feel for how the system works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking things down in the example to improve clarity looks good.
Codecov Report
@@ Coverage Diff @@
## master #1195 +/- ##
=======================================
Coverage 98.52% 98.52%
=======================================
Files 22 22
Lines 5695 5695
=======================================
Hits 5611 5611
Misses 84 84 Continue to review full report at Codecov.
|
@tleonhardt The lint check is failing on unrelated files. I think something in |
@anselor I merged in a fix for the |
@caseploeg Thank you for the PR! Please run |
Previously redirection information was lost by the postparsing hooks add_whitespace_hook() and downcase_hook(). This was fine for this simple shell, but sets a bad example for more complicated use cases. I made this mistake in my own application where I set up a hook to augment a Statement's arguments, but lost redirection information by accident. A very sticky bug to try and figure out why piping suddenly no longer works.
To fix this, when parsing the new Statement object, include the
post_command
attribute from the original Statement. I also made some slight organizational changes that should make it more obvious what's happening in the example.I also add a postcommand hook that hopefully provides some more intuition on the hook lifecycle by updating the prompt with the raw contents of the command last entered. I have this feature locked behind the debug option. I imagine this could help someone figure out the consequences of registering new hooks.
related to #1000