From 796e50ba3208b4dec9fbad26e4546d1ef2eea227 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Sat, 20 Dec 2014 15:33:48 -0800 Subject: [PATCH] cmd/mvpkg: a package moving tool This change adds a command mvpkg that will move a given package and update all its imports. It uses similar logic to gorename to update the imports. Change-Id: Iebbd0b4c93c2302b0a71c3b99c68f6778106012a Reviewed-on: https://go-review.googlesource.com/1973 Reviewed-by: Alan Donovan --- cmd/gomvpkg/main.go | 89 +++++++++ refactor/rename/check.go | 2 +- refactor/rename/mvpkg.go | 328 +++++++++++++++++++++++++++++++++ refactor/rename/mvpkg_test.go | 256 +++++++++++++++++++++++++ refactor/rename/rename.go | 42 +++++ refactor/rename/rename_test.go | 3 + 6 files changed, 719 insertions(+), 1 deletion(-) create mode 100644 cmd/gomvpkg/main.go create mode 100644 refactor/rename/mvpkg.go create mode 100644 refactor/rename/mvpkg_test.go diff --git a/cmd/gomvpkg/main.go b/cmd/gomvpkg/main.go new file mode 100644 index 00000000..86b8067f --- /dev/null +++ b/cmd/gomvpkg/main.go @@ -0,0 +1,89 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// licence that can be found in the LICENSE file. + +// The gomvpkg command moves go packages, updating import declarations. +// See the -help message or Usage constant for details. +package main + +import ( + "flag" + "fmt" + "go/build" + "os" + + "golang.org/x/tools/refactor/rename" +) + +var ( + fromFlag = flag.String("from", "", "Import path of package to be moved") + toFlag = flag.String("to", "", "Destination import path for package") + vcsMvCmdFlag = flag.String("vcs_mv_cmd", "", `A template for the version control system's "move directory" command, e.g. "git mv {{.Src}} {{.Dst}}`) + helpFlag = flag.Bool("help", false, "show usage message") +) + +const Usage = `gomvpkg: moves a package, updating import declarations + +Usage: + + gomvpkg -from -to [-vcs_mv_cmd