You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2017/03/06 21:44:12 UTC
[12/41] incubator-mynewt-newt git commit: add the pkg remove command
to newt
add the pkg remove command to newt
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/f497cab9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/f497cab9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/f497cab9
Branch: refs/heads/mynewt_1_0_0
Commit: f497cab99381fc00e4462d00fed45b5bba94819f
Parents: 2f04e25
Author: Sterling Hughes <st...@runtime.io>
Authored: Sat Feb 11 16:29:02 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 13:33:31 2017 -0800
----------------------------------------------------------------------
newt/cli/pkg_cmds.go | 72 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 69 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f497cab9/newt/cli/pkg_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/pkg_cmds.go b/newt/cli/pkg_cmds.go
index d04691e..75e9a00 100644
--- a/newt/cli/pkg_cmds.go
+++ b/newt/cli/pkg_cmds.go
@@ -29,6 +29,7 @@ import (
"github.com/spf13/cobra"
"mynewt.apache.org/newt/newt/interfaces"
"mynewt.apache.org/newt/newt/newtutil"
+ "mynewt.apache.org/newt/newt/pkg"
"mynewt.apache.org/newt/newt/project"
"mynewt.apache.org/newt/util"
)
@@ -60,11 +61,11 @@ func pkgMoveCmd(cmd *cobra.Command, args []string) {
wd, err := os.Getwd()
if err != nil {
- NewtUsage(cmd, util.NewNewtError(err.Error()))
+ NewtUsage(cmd, util.ChildNewtError(err))
}
if err := os.Chdir(proj.Path() + "/"); err != nil {
- NewtUsage(cmd, util.NewNewtError(err.Error()))
+ NewtUsage(cmd, util.ChildNewtError(err))
}
/* Find source package, defaulting search to the local project if no
@@ -149,12 +150,64 @@ func pkgMoveCmd(cmd *cobra.Command, args []string) {
os.Chdir(wd)
}
+func pkgRemoveCmd(cmd *cobra.Command, args []string) {
+ if len(args) != 1 {
+ NewtUsage(cmd, util.NewNewtError("Must specify a package name to delete"))
+ }
+
+ proj := TryGetProject()
+ interfaces.SetProject(proj)
+
+ wd, err := os.Getwd()
+ if err != nil {
+ NewtUsage(cmd, util.ChildNewtError(err))
+ }
+
+ if err := os.Chdir(proj.Path() + "/"); err != nil {
+ NewtUsage(cmd, util.ChildNewtError(err))
+ }
+ /* Resolve package, and get path from package to ensure we're being asked
+ * to remove a valid path.
+ */
+ repoName, pkgName, err := newtutil.ParsePackageString(args[0])
+ if err != nil {
+ os.Chdir(wd)
+ NewtUsage(cmd, err)
+ }
+
+ repo := proj.LocalRepo()
+ if repoName != "" {
+ repo = proj.FindRepo(repoName)
+ if repo == nil {
+ os.Chdir(wd)
+ NewtUsage(cmd, util.NewNewtError("Destination repo "+
+ repoName+" does not exist"))
+ }
+ }
+
+ pkg, err := pkg.LoadLocalPackage(repo, pkgName)
+ if err != nil {
+ os.Chdir(wd)
+ NewtUsage(cmd, err)
+ }
+
+ util.StatusMessage(util.VERBOSITY_DEFAULT, "Removing package %s\n",
+ args[0])
+
+ if err := os.RemoveAll(pkg.BasePath()); err != nil {
+ os.Chdir(wd)
+ NewtUsage(cmd, util.ChildNewtError(err))
+ }
+
+ os.Chdir(wd)
+}
+
func AddPackageCommands(cmd *cobra.Command) {
/* Add the base package command, on top of which other commands are
* keyed
*/
pkgHelpText := "Commands for creating and manipulating packages"
- pkgHelpEx := "newt pkg new --type=pkg libs/mylib"
+ pkgHelpEx := " newt pkg new --type=pkg libs/mylib"
pkgCmd := &cobra.Command{
Use: "pkg",
@@ -197,4 +250,17 @@ func AddPackageCommands(cmd *cobra.Command) {
}
pkgCmd.AddCommand(moveCmd)
+
+ removeCmdHelpText := ""
+ removeCmdHelpEx := ""
+
+ removeCmd := &cobra.Command{
+ Use: "remove",
+ Short: "Remove a package",
+ Long: removeCmdHelpText,
+ Example: removeCmdHelpEx,
+ Run: pkgRemoveCmd,
+ }
+
+ pkgCmd.AddCommand(removeCmd)
}