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 2016/03/09 21:23:39 UTC
[24/50] incubator-mynewt-newt git commit: Allow multiple targets in
delete command.
Allow multiple targets in delete command.
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/aef3d397
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/aef3d397
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/aef3d397
Branch: refs/heads/develop
Commit: aef3d397c82de355fa8a2511af204f9770af523d
Parents: d2d5ef1
Author: Christopher Collins <cc...@gmail.com>
Authored: Tue Mar 8 15:18:15 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Tue Mar 8 17:31:54 2016 -0800
----------------------------------------------------------------------
newt/target/cmds.go | 67 +++++++++++++++++++++++++++---------------------
1 file changed, 38 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/aef3d397/newt/target/cmds.go
----------------------------------------------------------------------
diff --git a/newt/target/cmds.go b/newt/target/cmds.go
index c55fd39..d831063 100644
--- a/newt/target/cmds.go
+++ b/newt/target/cmds.go
@@ -33,12 +33,14 @@ import (
"mynewt.apache.org/newt/util"
)
-// Type for sorting an array of target pointers alphabetically by name.
-type ByName []*Target
+func parseTargetName(arg string) (*Target, error) {
+ t := ResolveTargetName(arg)
+ if t == nil {
+ return nil, util.NewNewtError("Unknown target: " + arg)
+ }
-func (a ByName) Len() int { return len(a) }
-func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
-func (a ByName) Less(i, j int) bool { return a[i].Package().Name() < a[j].Package().Name() }
+ return t, nil
+}
func targetShowCmd(cmd *cobra.Command, args []string) {
proj := project.GetProject()
@@ -108,12 +110,10 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
}
// Parse target name.
- tName := args[0]
- t := ResolveTargetName(tName)
- if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("Unknown target: "+tName))
+ t, err := parseTargetName(args[0])
+ if err != nil {
+ cli.NewtUsage(cmd, err)
}
- tName = t.Name()
// Parse series of k=v pairs. If an argument doesn't contain a '='
// character, display the valid values for the variable and quit.
@@ -155,10 +155,11 @@ func targetSetCmd(cmd *cobra.Command, args []string) {
for _, kv := range vars {
if kv[1] == "" {
cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully unset %s\n", tName, kv[0])
+ "Target %s successfully unset %s\n", t.Name(), kv[0])
} else {
cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully set %s to %s\n", tName, kv[0], kv[1])
+ "Target %s successfully set %s to %s\n", t.Name(), kv[0],
+ kv[1])
}
}
}
@@ -198,22 +199,13 @@ func targetCreateCmd(cmd *cobra.Command, args []string) {
}
}
-func targetDelCmd(cmd *cobra.Command, args []string) {
- if len(args) < 1 {
- cli.NewtUsage(cmd, util.NewNewtError("Must specify target to delete"))
- }
-
- t := ResolveTargetName(args[0])
- if t == nil {
- cli.NewtUsage(cmd, util.NewNewtError("Target does not exist"))
- }
-
+func targetDelOne(t *Target) error {
if !cli.Force {
// Determine if the target directory contains extra user files. If it
// does, a prompt (or force) is required to delete it.
userFiles, err := t.ContainsUserFiles()
if err != nil {
- cli.NewtUsage(cmd, err)
+ return err
}
if userFiles {
@@ -222,20 +214,37 @@ func targetDelCmd(cmd *cobra.Command, args []string) {
"delete anyway? (y/N): ", t.basePkg.Name())
rc := scanner.Scan()
if !rc || strings.ToLower(scanner.Text()) != "y" {
- return
+ return nil
}
}
}
- // Clean target prior to deletion; ignore errors during clean.
- //t.BuildClean(false)
-
if err := t.Delete(); err != nil {
- cli.NewtUsage(cmd, err)
+ return err
}
cli.StatusMessage(cli.VERBOSITY_DEFAULT,
- "Target %s successfully removed\n", args[0])
+ "Target %s successfully removed\n", t.Name())
+
+ return nil
+}
+
+func targetDelCmd(cmd *cobra.Command, args []string) {
+ if len(args) < 1 {
+ cli.NewtUsage(cmd, util.NewNewtError("Must specify at least one "+
+ "target to delete"))
+ }
+
+ targets, err := ResolveTargetNames(args...)
+ if err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+
+ for _, t := range targets {
+ if err := targetDelOne(t); err != nil {
+ cli.NewtUsage(cmd, err)
+ }
+ }
}
func AddCommands(cmd *cobra.Command) {