This repository was archived by the owner on Jul 12, 2020. It is now read-only.
Allow stdin input for single file refactors#69
Open
LeighBicknell wants to merge 3 commits intoQafooLabs:masterfrom
Open
Allow stdin input for single file refactors#69LeighBicknell wants to merge 3 commits intoQafooLabs:masterfrom
LeighBicknell wants to merge 3 commits intoQafooLabs:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allowing stdin input has many uses and is, in my opinion essential.
I'm not familiar with the codebase, but I came up with these changes to support stdin.
Example of use:
$ cat home.php | php refactor.phar extract-method - 7-7 myNewFunction(obviously this isn't a great example of a use case)
Replacing the filename parameter with
-will tell refactor.phar to use stdin as the file contents instead of a specific file.As most commands have a dependency on the File class, it will create a tmpfile() with the stdin contents, and then create a File object from the temporary file. I've added a static File::createFromContents() function to facilitate this.
Use cases are numerous, but my specific use case/reason for implementation is for the vim-php-refactoring plugin (i've also forked to support this change). Which has multiple restrictions thrust upon it due to php-refactoring-browser not supporting stdin input.
Example:
:%!php refactor.phar extract-method - 7-7 myNewFunction | patch --silent --ouput=- --dir="/tmp"This allows on-the-fly refactoring of modified vim buffers, without worrying about loosing unsaved buffer changes, or directly modifying and having the reload the file on disk. It makes the whole experience much more seamless.