Re: [go-nuts] Re: Replace reference path

2022-10-31 Thread mr....@gmail.com
I think this tool just needs to be replaced from what to what.

For example this looks like this

goreplacepkg -from 
k8s.io/apimachinery/pkg/util/diff.{ObjectDiff,ObjectGoPrintDiff,ObjectGoPrintDiff}
 
-to  github.com/google/go-cmp/cmp.Diff

goreplacepkg -from ioutil.ReadAll -to  io.ReadAll

Here we think his parameters are the same, then the tool just needs to 
parse the go file, find the path of the import in this go file, and the 
methods under this path. Then do the replacement,Finally a new file is 
generated, github.com/google/go-cmp/cmp is added to import, and the 
original k8s.io/apimachinery/pkg/util/diff can be removed if he is no 
longer used.

For example, the input file would look like this

package test

import "k8s.io/apimachinery/pkg/util/diff"

func A()string{
var a = "test"
 var b = "test1"
 return diff.ObjectDiff(a,b)
}

func B()string{
  var a = "test"
  var b= 'test1"
  return diff.ObjectGoPrintSideBySide(a,b)
}



Execution of commands
goreplacepkg -from k8s.io/apimachinery/pkg/util/diff.ObjectDiff -to 
 github.com/google/go-cmp/cmp.Diff

The final file he generates may look like this

package test

import  (
"k8s.io/apimachinery/pkg/util/diff"
"github.com/google/go-cmp/cmp"
)

func A()string{
var a = "test"
 var b = "test1"
 return cmp.Diff(a,b)
}

func B()string{
  var a = "test"
  var b= 'test1"
  return diff.ObjectGoPrintSideBySide(a,b)
}


He doesn't need to know the go version, he just needs the user to pass in 
the input and output



在2022年11月1日星期二 UTC+8 13:51:07 写道:

> https://k8s.io/apimachinery/pkg/util/diff?go-get=1
>
> He needs to add parameters to be able to access
>
>
> https://github.com/kubernetes/apimachinery/blob/master/pkg/util/diff/diff.go#L57
>
> This is his path to realization
> 在2022年11月1日星期二 UTC+8 12:41:22 写道:
>
>> On Mon, Oct 31, 2022 at 8:27 PM mr@gmail.com  
>> wrote:
>>
>>> Yes, it is very rare, but it can be encountered, and once encountered 
>>> his workload will be a lot of
>>>
>>> github.com/pkg/errors > std.errors
>>> ioutil.TempDir => os.MkdirTemp
>>> ioutil.ReadAll  => io.ReadAll
>>>
>>
>> You seem to agree with me that such refactorings are extremely rare. 
>> Furthermore, your ioutil.TempDir to os.MkdirTemp example is a trivial 
>> substitution since the API didn't change -- only the preferred function 
>> name changed. How many programs include more than a single call to the now 
>> deprecated ioutil.TempDir function? And how much work is it for the people 
>> maintaining those projects to manually make the required substitutions? How 
>> much work would be saved even if those people were aware of such a tool? 
>>
>> Your real question seems to be "Is there a tool that replaces a 
>> deprecated API with the preferred API?" I am not aware of such a tool. 
>> Furthermore, such a tool would have to be aware of the minimum Go version 
>> supported by a project and whether a particular dependency can be updated. 
>> The mechanical substitution of the API is trivial compared to determining 
>> whether the substitution is appropriate. Also, the substitution is only 
>> possible if the API is unchanged -- only the preferred symbols are changed.
>>
>> I also note that none of the links in your initial message are valid. So 
>> I can't determine whether they are a trivial renaming of an API or the 
>> changes are more substantive.
>>
>>
>> 在2022年10月31日星期一 UTC+8 10:52:45 写道:
>>>
 I'm curious how often you perform such refactoring? In my experience 
 such changes are extremely rare and usually require other changes due to 
 differences in the API of the two third-party packages . Which means, in 
 my 
 experience, expending effort to automate such import rewrites typically 
 requires more effort than just doing it "by hand". The gomvpkg tool is 
 meant to solve a more common problem that does happen with some 
 regularity. 
 Namely, changing the paths of packages private to a particular project as 
 that project evolves. Which is why that tool "doesn't get the job done" 
 for 
 your situation.  

 On Sun, Oct 30, 2022 at 7:22 PM mr@gmail.com  
 wrote:

> He doesn't get the job done.
>
> 在2022年10月22日星期六 UTC+8 06:20:53 写道:
>
>> try https://pkg.go.dev/golang.org/x/tools/cmd/gomvpkg
>>
>>
>> On Friday, 21 October 2022 at 16:58:57 UTC+1 mr@gmail.com wrote:
>>
>>> I'm looking for a tool like this, I've searched google and github 
>>> and can't find one, have you guys used such a tool?
>>>
>>> I use a method like this in my code
>>>
>>> k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff
>>>
>>> k8s.io/apimachinery/pkg/util/diff is his import path, later I want 
>>> to switch to another method.
>>>
>>> github.com/google/go-cmp/cmp.Diff
>>>
>>> github.com/google/go-cmp/cmp is his import path.
>>>
>>> I would like to ask if there is a more convenient

Re: [go-nuts] Re: Replace reference path

2022-10-31 Thread mr....@gmail.com
https://k8s.io/apimachinery/pkg/util/diff?go-get=1

He needs to add parameters to be able to access

https://github.com/kubernetes/apimachinery/blob/master/pkg/util/diff/diff.go#L57

This is his path to realization
在2022年11月1日星期二 UTC+8 12:41:22 写道:

> On Mon, Oct 31, 2022 at 8:27 PM mr@gmail.com  wrote:
>
>> Yes, it is very rare, but it can be encountered, and once encountered his 
>> workload will be a lot of
>>
>> github.com/pkg/errors > std.errors
>> ioutil.TempDir => os.MkdirTemp
>> ioutil.ReadAll  => io.ReadAll
>>
>
> You seem to agree with me that such refactorings are extremely rare. 
> Furthermore, your ioutil.TempDir to os.MkdirTemp example is a trivial 
> substitution since the API didn't change -- only the preferred function 
> name changed. How many programs include more than a single call to the now 
> deprecated ioutil.TempDir function? And how much work is it for the people 
> maintaining those projects to manually make the required substitutions? How 
> much work would be saved even if those people were aware of such a tool? 
>
> Your real question seems to be "Is there a tool that replaces a deprecated 
> API with the preferred API?" I am not aware of such a tool. Furthermore, 
> such a tool would have to be aware of the minimum Go version supported by a 
> project and whether a particular dependency can be updated. The mechanical 
> substitution of the API is trivial compared to determining whether the 
> substitution is appropriate. Also, the substitution is only possible if the 
> API is unchanged -- only the preferred symbols are changed.
>
> I also note that none of the links in your initial message are valid. So I 
> can't determine whether they are a trivial renaming of an API or the 
> changes are more substantive.
>
>
> 在2022年10月31日星期一 UTC+8 10:52:45 写道:
>>
>>> I'm curious how often you perform such refactoring? In my experience 
>>> such changes are extremely rare and usually require other changes due to 
>>> differences in the API of the two third-party packages . Which means, in my 
>>> experience, expending effort to automate such import rewrites typically 
>>> requires more effort than just doing it "by hand". The gomvpkg tool is 
>>> meant to solve a more common problem that does happen with some regularity. 
>>> Namely, changing the paths of packages private to a particular project as 
>>> that project evolves. Which is why that tool "doesn't get the job done" for 
>>> your situation.  
>>>
>>> On Sun, Oct 30, 2022 at 7:22 PM mr@gmail.com  
>>> wrote:
>>>
 He doesn't get the job done.

 在2022年10月22日星期六 UTC+8 06:20:53 写道:

> try https://pkg.go.dev/golang.org/x/tools/cmd/gomvpkg
>
>
> On Friday, 21 October 2022 at 16:58:57 UTC+1 mr@gmail.com wrote:
>
>> I'm looking for a tool like this, I've searched google and github and 
>> can't find one, have you guys used such a tool?
>>
>> I use a method like this in my code
>>
>> k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff
>>
>> k8s.io/apimachinery/pkg/util/diff is his import path, later I want 
>> to switch to another method.
>>
>> github.com/google/go-cmp/cmp.Diff
>>
>> github.com/google/go-cmp/cmp is his import path.
>>
>> I would like to ask if there is a more convenient tool for replacing 
>> the whole project?
>>
>> k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff -> 
>> github.com/google/go-cmp/cmp.Diff
>
>  
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/93e00ff8-1ebd-418d-b07e-8f97ab4e1426n%40googlegroups.com.


Re: [go-nuts] Re: Replace reference path

2022-10-31 Thread Kurtis Rader
On Mon, Oct 31, 2022 at 8:27 PM mr@gmail.com  wrote:

> Yes, it is very rare, but it can be encountered, and once encountered his
> workload will be a lot of
>
> github.com/pkg/errors > std.errors
> ioutil.TempDir => os.MkdirTemp
> ioutil.ReadAll  => io.ReadAll
>

You seem to agree with me that such refactorings are extremely rare.
Furthermore, your ioutil.TempDir to os.MkdirTemp example is a trivial
substitution since the API didn't change -- only the preferred function
name changed. How many programs include more than a single call to the now
deprecated ioutil.TempDir function? And how much work is it for the people
maintaining those projects to manually make the required substitutions? How
much work would be saved even if those people were aware of such a tool?

Your real question seems to be "Is there a tool that replaces a deprecated
API with the preferred API?" I am not aware of such a tool. Furthermore,
such a tool would have to be aware of the minimum Go version supported by a
project and whether a particular dependency can be updated. The mechanical
substitution of the API is trivial compared to determining whether the
substitution is appropriate. Also, the substitution is only possible if the
API is unchanged -- only the preferred symbols are changed.

I also note that none of the links in your initial message are valid. So I
can't determine whether they are a trivial renaming of an API or the
changes are more substantive.


在2022年10月31日星期一 UTC+8 10:52:45 写道:
>
>> I'm curious how often you perform such refactoring? In my experience such
>> changes are extremely rare and usually require other changes due to
>> differences in the API of the two third-party packages . Which means, in my
>> experience, expending effort to automate such import rewrites typically
>> requires more effort than just doing it "by hand". The gomvpkg tool is
>> meant to solve a more common problem that does happen with some regularity.
>> Namely, changing the paths of packages private to a particular project as
>> that project evolves. Which is why that tool "doesn't get the job done" for
>> your situation.
>>
>> On Sun, Oct 30, 2022 at 7:22 PM mr@gmail.com 
>> wrote:
>>
>>> He doesn't get the job done.
>>>
>>> 在2022年10月22日星期六 UTC+8 06:20:53 写道:
>>>
 try https://pkg.go.dev/golang.org/x/tools/cmd/gomvpkg


 On Friday, 21 October 2022 at 16:58:57 UTC+1 mr@gmail.com wrote:

> I'm looking for a tool like this, I've searched google and github and
> can't find one, have you guys used such a tool?
>
> I use a method like this in my code
>
> k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff
>
> k8s.io/apimachinery/pkg/util/diff is his import path, later I want to
> switch to another method.
>
> github.com/google/go-cmp/cmp.Diff
>
> github.com/google/go-cmp/cmp is his import path.
>
> I would like to ask if there is a more convenient tool for replacing
> the whole project?
>
> k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff ->
> github.com/google/go-cmp/cmp.Diff


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD-006wi7seJowPM0QOCn%2B2XnPPYnVyjwT4fy25hvw_%3Ddw%40mail.gmail.com.


Re: [go-nuts] Re: Replace reference path

2022-10-31 Thread mr....@gmail.com
Yes, it is very rare, but it can be encountered, and once encountered his 
workload will be a lot of

github.com/pkg/errors > std.errors
ioutil.TempDir => os.MkdirTemp
ioutil.ReadAll  => io.ReadAll




在2022年10月31日星期一 UTC+8 10:52:45 写道:

> I'm curious how often you perform such refactoring? In my experience such 
> changes are extremely rare and usually require other changes due to 
> differences in the API of the two third-party packages . Which means, in my 
> experience, expending effort to automate such import rewrites typically 
> requires more effort than just doing it "by hand". The gomvpkg tool is 
> meant to solve a more common problem that does happen with some regularity. 
> Namely, changing the paths of packages private to a particular project as 
> that project evolves. Which is why that tool "doesn't get the job done" for 
> your situation.  
>
> On Sun, Oct 30, 2022 at 7:22 PM mr@gmail.com  wrote:
>
>> He doesn't get the job done.
>>
>> 在2022年10月22日星期六 UTC+8 06:20:53 写道:
>>
>>> try https://pkg.go.dev/golang.org/x/tools/cmd/gomvpkg
>>>
>>>
>>> On Friday, 21 October 2022 at 16:58:57 UTC+1 mr@gmail.com wrote:
>>>
 I'm looking for a tool like this, I've searched google and github and 
 can't find one, have you guys used such a tool?

 I use a method like this in my code

 k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff

 k8s.io/apimachinery/pkg/util/diff is his import path, later I want to 
 switch to another method.

 github.com/google/go-cmp/cmp.Diff

 github.com/google/go-cmp/cmp is his import path.

 I would like to ask if there is a more convenient tool for replacing 
 the whole project?

 k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff -> 
 github.com/google/go-cmp/cmp.Diff

>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/695f32a0-009c-4415-b856-71bd4792385dn%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5502f871-4984-4f9d-8976-ac948c45e849n%40googlegroups.com.


Re: [go-nuts] Re: Replace reference path

2022-10-30 Thread Kurtis Rader
I'm curious how often you perform such refactoring? In my experience such
changes are extremely rare and usually require other changes due to
differences in the API of the two third-party packages . Which means, in my
experience, expending effort to automate such import rewrites typically
requires more effort than just doing it "by hand". The gomvpkg tool is
meant to solve a more common problem that does happen with some regularity.
Namely, changing the paths of packages private to a particular project as
that project evolves. Which is why that tool "doesn't get the job done" for
your situation.

On Sun, Oct 30, 2022 at 7:22 PM mr@gmail.com  wrote:

> He doesn't get the job done.
>
> 在2022年10月22日星期六 UTC+8 06:20:53 写道:
>
>> try https://pkg.go.dev/golang.org/x/tools/cmd/gomvpkg
>>
>>
>> On Friday, 21 October 2022 at 16:58:57 UTC+1 mr@gmail.com wrote:
>>
>>> I'm looking for a tool like this, I've searched google and github and
>>> can't find one, have you guys used such a tool?
>>>
>>> I use a method like this in my code
>>>
>>> k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff
>>>
>>> k8s.io/apimachinery/pkg/util/diff is his import path, later I want to
>>> switch to another method.
>>>
>>> github.com/google/go-cmp/cmp.Diff
>>>
>>> github.com/google/go-cmp/cmp is his import path.
>>>
>>> I would like to ask if there is a more convenient tool for replacing the
>>> whole project?
>>>
>>> k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff ->
>>> github.com/google/go-cmp/cmp.Diff
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/695f32a0-009c-4415-b856-71bd4792385dn%40googlegroups.com
> 
> .
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD_eJ%2B-HLbJEQipjbNw77bAnhHCxP5i_t3xb%3D4NAFakHCw%40mail.gmail.com.


[go-nuts] Re: Replace reference path

2022-10-30 Thread mr....@gmail.com
He doesn't get the job done.

在2022年10月22日星期六 UTC+8 06:20:53 写道:

> try https://pkg.go.dev/golang.org/x/tools/cmd/gomvpkg
>
>
> On Friday, 21 October 2022 at 16:58:57 UTC+1 mr@gmail.com wrote:
>
>> I'm looking for a tool like this, I've searched google and github and 
>> can't find one, have you guys used such a tool?
>>
>> I use a method like this in my code
>>
>> k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff
>>
>> k8s.io/apimachinery/pkg/util/diff is his import path, later I want to 
>> switch to another method.
>>
>> github.com/google/go-cmp/cmp.Diff
>>
>> github.com/google/go-cmp/cmp is his import path.
>>
>> I would like to ask if there is a more convenient tool for replacing the 
>> whole project?
>>
>> k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff -> 
>> github.com/google/go-cmp/cmp.Diff
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/695f32a0-009c-4415-b856-71bd4792385dn%40googlegroups.com.


[go-nuts] Re: Replace reference path

2022-10-21 Thread Amnon
try https://pkg.go.dev/golang.org/x/tools/cmd/gomvpkg


On Friday, 21 October 2022 at 16:58:57 UTC+1 mr@gmail.com wrote:

> I'm looking for a tool like this, I've searched google and github and 
> can't find one, have you guys used such a tool?
>
> I use a method like this in my code
>
> k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff
>
> k8s.io/apimachinery/pkg/util/diff is his import path, later I want to 
> switch to another method.
>
> github.com/google/go-cmp/cmp.Diff
>
> github.com/google/go-cmp/cmp is his import path.
>
> I would like to ask if there is a more convenient tool for replacing the 
> whole project?
>
> k8s.io/apimachinery/pkg/util/diff.ObjectReflectDiff -> 
> github.com/google/go-cmp/cmp.Diff
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/57c42d1b-32a5-4e69-95dc-1e0264d8988bn%40googlegroups.com.