mirror of
https://github.com/golang/go
synced 2024-11-18 18:54:42 -07:00
internal/lsp/cmd: don't create .orig files for rename by default
Fixes golang/go#35551 Change-Id: I78086e0288da84a4c0b008d05e376f47b30d978a Reviewed-on: https://go-review.googlesource.com/c/tools/+/207347 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
11e13f1c3f
commit
6d480e29d4
@ -23,8 +23,9 @@ import (
|
||||
|
||||
// rename implements the rename verb for gopls.
|
||||
type rename struct {
|
||||
Diff bool `flag:"d" help:"display diffs instead of rewriting files"`
|
||||
Write bool `flag:"w" help:"write result to (source) file instead of stdout"`
|
||||
Diff bool `flag:"d" help:"display diffs instead of rewriting files"`
|
||||
Write bool `flag:"w" help:"write result to (source) file instead of stdout"`
|
||||
Preserve bool `flag:"preserve" help:"preserve original files"`
|
||||
|
||||
app *Application
|
||||
}
|
||||
@ -102,9 +103,10 @@ func (r *rename) Run(ctx context.Context, args ...string) error {
|
||||
switch {
|
||||
case r.Write:
|
||||
fmt.Fprintln(os.Stderr, filename)
|
||||
err := os.Rename(filename, filename+".orig")
|
||||
if err != nil {
|
||||
return errors.Errorf("%v: %v", edits, err)
|
||||
if r.Preserve {
|
||||
if err := os.Rename(filename, filename+".orig"); err != nil {
|
||||
return errors.Errorf("%v: %v", edits, err)
|
||||
}
|
||||
}
|
||||
ioutil.WriteFile(filename, []byte(newContent), 0644)
|
||||
case r.Diff:
|
||||
|
Loading…
Reference in New Issue
Block a user