You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/12/06 00:39:08 UTC

incubator-mynewt-newt git commit: MYNEWT-503 newt - No status or log msgs at init

Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop 51906cf25 -> 7407ff141


MYNEWT-503 newt - No status or log msgs at init

No log messages or status messages are displayed while the project is
being initialized.  This issue is related to tab completion: output is
intentionally suppressed during initialization so that the "complete"
command generates clean output.

The fix is to only generate valid tab completion values when it has been
determined that the "complete" command is being used.


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/7407ff14
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/7407ff14
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/7407ff14

Branch: refs/heads/develop
Commit: 7407ff141f2c696afc857b1638441a7d24008751
Parents: 51906cf
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Dec 5 16:34:23 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Dec 5 16:34:23 2016 -0800

----------------------------------------------------------------------
 newt/cli/build_cmds.go   | 23 +++++++++++++++--------
 newt/cli/complete_cmd.go | 19 +++++++++++++++++++
 newt/cli/image_cmds.go   |  2 +-
 newt/cli/mfg_cmds.go     | 24 ++++++++++++------------
 newt/cli/run_cmds.go     |  2 +-
 newt/cli/target_cmds.go  | 28 +++++++++++++++-------------
 newt/newt.go             |  1 +
 7 files changed, 64 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7407ff14/newt/cli/build_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/build_cmds.go b/newt/cli/build_cmds.go
index 112e9a3..0951eda 100644
--- a/newt/cli/build_cmds.go
+++ b/newt/cli/build_cmds.go
@@ -367,8 +367,10 @@ func AddBuildCommands(cmd *cobra.Command) {
 		Run:   buildRunCmd,
 	}
 
-	buildCmd.ValidArgs = targetList()
 	cmd.AddCommand(buildCmd)
+	AddTabCompleteFn(buildCmd, func() []string {
+		return append(targetList(), "all")
+	})
 
 	cleanCmd := &cobra.Command{
 		Use:   "clean <target-name> [target-names...] | all",
@@ -376,16 +378,20 @@ func AddBuildCommands(cmd *cobra.Command) {
 		Run:   cleanRunCmd,
 	}
 
-	cleanCmd.ValidArgs = append(targetList(), "all")
 	cmd.AddCommand(cleanCmd)
+	AddTabCompleteFn(cleanCmd, func() []string {
+		return append(targetList(), "all")
+	})
 
 	testCmd := &cobra.Command{
 		Use:   "test <package-name> [package-names...] | all",
 		Short: "Executes unit tests for one or more packages",
 		Run:   testRunCmd,
 	}
-	testCmd.ValidArgs = append(testablePkgList(), "all")
 	cmd.AddCommand(testCmd)
+	AddTabCompleteFn(testCmd, func() []string {
+		return append(testablePkgList(), "all")
+	})
 
 	loadHelpText := "Load app image to target for <target-name>."
 
@@ -396,8 +402,9 @@ func AddBuildCommands(cmd *cobra.Command) {
 		Run:   loadRunCmd,
 	}
 
-	loadCmd.ValidArgs = targetList()
 	cmd.AddCommand(loadCmd)
+	AddTabCompleteFn(loadCmd, targetList)
+
 	loadCmd.PersistentFlags().StringVarP(&extraJtagCmd, "extrajtagcmd", "j", "",
 		"extra commands to send to JTAG software")
 
@@ -410,13 +417,14 @@ func AddBuildCommands(cmd *cobra.Command) {
 		Run:   debugRunCmd,
 	}
 
-	debugCmd.ValidArgs = targetList()
-	cmd.AddCommand(debugCmd)
 	debugCmd.PersistentFlags().StringVarP(&extraJtagCmd, "extrajtagcmd", "j", "",
 		"extra commands to send to JTAG software")
 	debugCmd.PersistentFlags().BoolVarP(&noGDB_flag, "noGDB", "n", false,
 		"don't start GDB from command line")
 
+	cmd.AddCommand(debugCmd)
+	AddTabCompleteFn(debugCmd, targetList)
+
 	sizeHelpText := "Calculate the size of target components specified by " +
 		"<target-name>."
 
@@ -427,7 +435,6 @@ func AddBuildCommands(cmd *cobra.Command) {
 		Run:   sizeRunCmd,
 	}
 
-	sizeCmd.ValidArgs = targetList()
 	cmd.AddCommand(sizeCmd)
-
+	AddTabCompleteFn(sizeCmd, targetList)
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7407ff14/newt/cli/complete_cmd.go
----------------------------------------------------------------------
diff --git a/newt/cli/complete_cmd.go b/newt/cli/complete_cmd.go
index 4235851..272f928 100644
--- a/newt/cli/complete_cmd.go
+++ b/newt/cli/complete_cmd.go
@@ -33,6 +33,25 @@ import (
 	"github.com/spf13/pflag"
 )
 
+type TabCompleteFn func() []string
+
+var tabCompleteEntries = map[*cobra.Command]TabCompleteFn{}
+
+func AddTabCompleteFn(cmd *cobra.Command, cb TabCompleteFn) {
+	if cmd.ValidArgs != nil || tabCompleteEntries[cmd] != nil {
+		panic("tab completion values generated twice for command " +
+			cmd.Name())
+	}
+
+	tabCompleteEntries[cmd] = cb
+}
+
+func GenerateTabCompleteValues() {
+	for cmd, cb := range tabCompleteEntries {
+		cmd.ValidArgs = cb()
+	}
+}
+
 func pkgNameList(filterCb func(*pkg.LocalPackage) bool) []string {
 	names := []string{}
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7407ff14/newt/cli/image_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/image_cmds.go b/newt/cli/image_cmds.go
index dac2fc2..ced97a5 100644
--- a/newt/cli/image_cmds.go
+++ b/newt/cli/image_cmds.go
@@ -85,6 +85,6 @@ func AddImageCommands(cmd *cobra.Command) {
 		Run:     createImageRunCmd,
 	}
 
-	createImageCmd.ValidArgs = targetList()
 	cmd.AddCommand(createImageCmd)
+	AddTabCompleteFn(createImageCmd, targetList)
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7407ff14/newt/cli/mfg_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/mfg_cmds.go b/newt/cli/mfg_cmds.go
index 78a2299..849e4d0 100644
--- a/newt/cli/mfg_cmds.go
+++ b/newt/cli/mfg_cmds.go
@@ -156,26 +156,26 @@ func AddMfgCommands(cmd *cobra.Command) {
 	cmd.AddCommand(mfgCmd)
 
 	mfgCreateCmd := &cobra.Command{
-		Use:       "create <mfg-package-name>",
-		Short:     "Create a manufacturing flash image",
-		Run:       mfgCreateRunCmd,
-		ValidArgs: mfgList(),
+		Use:   "create <mfg-package-name>",
+		Short: "Create a manufacturing flash image",
+		Run:   mfgCreateRunCmd,
 	}
 	mfgCmd.AddCommand(mfgCreateCmd)
+	AddTabCompleteFn(mfgCreateCmd, mfgList)
 
 	mfgLoadCmd := &cobra.Command{
-		Use:       "load <mfg-package-name>",
-		Short:     "Load a manufacturing flash image onto a device",
-		Run:       mfgLoadRunCmd,
-		ValidArgs: mfgList(),
+		Use:   "load <mfg-package-name>",
+		Short: "Load a manufacturing flash image onto a device",
+		Run:   mfgLoadRunCmd,
 	}
 	mfgCmd.AddCommand(mfgLoadCmd)
+	AddTabCompleteFn(mfgLoadCmd, mfgList)
 
 	mfgDeployCmd := &cobra.Command{
-		Use:       "deploy <mfg-package-name>",
-		Short:     "Builds and uploads a manufacturing image (build + load)",
-		Run:       mfgDeployRunCmd,
-		ValidArgs: mfgList(),
+		Use:   "deploy <mfg-package-name>",
+		Short: "Builds and uploads a manufacturing image (build + load)",
+		Run:   mfgDeployRunCmd,
 	}
 	mfgCmd.AddCommand(mfgDeployCmd)
+	AddTabCompleteFn(mfgDeployCmd, mfgList)
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7407ff14/newt/cli/run_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/run_cmds.go b/newt/cli/run_cmds.go
index ee72e87..3d94bd5 100644
--- a/newt/cli/run_cmds.go
+++ b/newt/cli/run_cmds.go
@@ -91,8 +91,8 @@ func AddRunCommands(cmd *cobra.Command) {
 		Example: runHelpEx,
 		Run:     runRunCmd,
 	}
-	runCmd.ValidArgs = targetList()
 	cmd.AddCommand(runCmd)
+	AddTabCompleteFn(runCmd, targetList)
 
 	runCmd.PersistentFlags().StringVarP(&extraJtagCmd, "extrajtagcmd", "j", "",
 		"extra commands to send to JTAG software")

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7407ff14/newt/cli/target_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go
index 09cd881..4b19bbf 100644
--- a/newt/cli/target_cmds.go
+++ b/newt/cli/target_cmds.go
@@ -548,8 +548,8 @@ func AddTargetCommands(cmd *cobra.Command) {
 		Example: showHelpEx,
 		Run:     targetShowCmd,
 	}
-	showCmd.ValidArgs = targetList()
 	targetCmd.AddCommand(showCmd)
+	AddTabCompleteFn(showCmd, targetList)
 
 	setHelpText := "Set a target variable (<var-name>) on target " +
 		"<target-name> to value <value>."
@@ -565,8 +565,8 @@ func AddTargetCommands(cmd *cobra.Command) {
 		Example: setHelpEx,
 		Run:     targetSetCmd,
 	}
-	setCmd.ValidArgs = targetList()
 	targetCmd.AddCommand(setCmd)
+	AddTabCompleteFn(setCmd, targetList)
 
 	createHelpText := "Create a target specified by <target-name>."
 	createHelpEx := "  newt target create <target-name>\n"
@@ -603,25 +603,27 @@ func AddTargetCommands(cmd *cobra.Command) {
 	copyHelpEx += "  newt target copy blinky_sim my_target"
 
 	copyCmd := &cobra.Command{
-		Use:       "copy",
-		Short:     "Copy target",
-		Long:      copyHelpText,
-		Example:   copyHelpEx,
-		Run:       targetCopyCmd,
-		ValidArgs: targetList(),
+		Use:     "copy",
+		Short:   "Copy target",
+		Long:    copyHelpText,
+		Example: copyHelpEx,
+		Run:     targetCopyCmd,
 	}
 
 	targetCmd.AddCommand(copyCmd)
+	AddTabCompleteFn(copyCmd, targetList)
 
 	configHelpText := "View a target's system configuration."
 
 	configCmd := &cobra.Command{
-		Use:       "config",
-		Short:     "View target system configuration",
-		Long:      configHelpText,
-		Run:       targetConfigCmd,
-		ValidArgs: append(targetList(), unittestList()...),
+		Use:   "config",
+		Short: "View target system configuration",
+		Long:  configHelpText,
+		Run:   targetConfigCmd,
 	}
 
 	targetCmd.AddCommand(configCmd)
+	AddTabCompleteFn(configCmd, func() []string {
+		return append(targetList(), unittestList()...)
+	})
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/7407ff14/newt/newt.go
----------------------------------------------------------------------
diff --git a/newt/newt.go b/newt/newt.go
index 64fa13c..e7a4ab0 100644
--- a/newt/newt.go
+++ b/newt/newt.go
@@ -135,6 +135,7 @@ func main() {
 		os.Args = tmpArgs[0:2]
 
 		if err == nil && bc.Name() == "complete" {
+			cli.GenerateTabCompleteValues()
 			bc.Execute()
 			return
 		}