hello good day,
I just want to ask what is the proper way of renaming go code?
example I have this.
on the directory
// New is a new package
then I tried to rename it using
gorename -from '"github.com/samp/pack".pack.New' -to New1 but I got always
gorename: -from '"github.com/samp/pack.pack.New"': invalid expression I already tried to remove the
pack but still the same
BTW I want also to ask if there a good blog or documentation about gorename? I cant find any.
-from path seems to double the package name. Try
I still get the same result
gorename: -from "'github.com/samp/pack.New'": invalid expression.
btw i am on windows 10.
Put the double quotes only around the package path. I don’t know why but gorename wants it that way…
Yes I did, the double quotes is on the path only. but until now still I didn’t resolved it. I dont know what I am missing here.
I already reinstalled gorename many times, got till the same result.
This is strange. I tested gorename on my end (even with the same path, file name and file contents that you posted here), and it works without problems.
Did you double-check if the GOPATH is set in the Command Prompt window where you run gorename? (
go env GOPATH)
Otherwise it could indeed be an OS-specific issue - I tested on a Mac.
In this case, try the -v option to make gorename chattier.
That is what I am thinking, I also try it on a fresh Win 10 install on hyper-v got same result. I will download Ubuntu, try it there.
-offset sometimes will work sometimes will now but most of the time it will say
no identifier at this position on Emacs and the stranger is sometimes it will rename the other variable on the same line.
I can successfully rename it using atom with go-rename package, but I don’t like opening atom just to do a rename.
BTW I took print screen, the
-v option doesn’t give any more details.
I suspect a quoting issue. On unixes, the
-from '"github.com/samp/pack".New' thing will have the outer set of quotes removed (i.e., interpreted) by the shell and sent to the program as
"github.com/samp/pack".New while your command on Windows will probably send the actual single quotes as well to the program.
Good point. This would explain why the error message still contains the single quotes (wrapped into a new pair of double quotes).
(As a side note, this also reveals that my second reply was quite pointless - I was not aware that the gorename error message removes the double quotes around the path, and adds new double quotes around everything instead.)
@christophberger @calmh Thank you so much, I tried bash instead of cmd or powershell and it works.
I dont know if its a bug on gorename or there is something wrong with the image copy of my windows os.
Glad to hear you found a workaround.
It is maybe not a bug in gorename, but it might qualify as an enhancement request.
Just a follow up.
In order gorename to work on command prompt just remove the single quotes and escape the double quotes, while on powershell just escape the double quotes.
gorename -from \"github.com/samp/pack\".New -to New1
gorename -from '\"github.com/samp/pack\".New' -to New1
github issue #20422
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.