search and replace package name instead of rewriting package
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/a6d1a667 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/a6d1a667 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/a6d1a667 Branch: refs/heads/master Commit: a6d1a667e6b6138849409c3c56deb98fa0fc4728 Parents: 9c9a777 Author: Sterling Hughes <[email protected]> Authored: Sat Feb 11 15:48:37 2017 -0800 Committer: Sterling Hughes <[email protected]> Committed: Sat Feb 11 15:48:37 2017 -0800 ---------------------------------------------------------------------- newt/cli/pkg_cmds.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/a6d1a667/newt/cli/pkg_cmds.go ---------------------------------------------------------------------- diff --git a/newt/cli/pkg_cmds.go b/newt/cli/pkg_cmds.go index 0b05f05..13937d6 100644 --- a/newt/cli/pkg_cmds.go +++ b/newt/cli/pkg_cmds.go @@ -20,8 +20,10 @@ package cli import ( + "io/ioutil" "os" "path" + "regexp" "strings" "github.com/spf13/cobra" @@ -123,6 +125,20 @@ func pkgMoveCmd(cmd *cobra.Command, args []string) { NewtUsage(cmd, err) } + /* Replace the package name in the pkg.yml file */ + pkgData, err := ioutil.ReadFile(dstPath + "/pkg.yml") + if err != nil { + os.Chdir(wd) + NewtUsage(cmd, err) + } + + re := regexp.MustCompile(regexp.QuoteMeta(srcName)) + res := re.ReplaceAllString(string(pkgData), pkgName) + + if err := ioutil.WriteFile(dstPath+"/pkg.yml", []byte(res), 0666); err != nil { + NewtUsage(cmd, util.ChildNewtError(err)) + } + dstPkg, err := pkg.LoadLocalPackage(repo, pkgName) if err != nil { os.Chdir(wd)
