You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2022/09/15 10:40:23 UTC
[mynewt-newt] branch master updated: Add command to list available targets
This is an automated email from the ASF dual-hosted git repository.
andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
The following commit(s) were added to refs/heads/master by this push:
new 6e23bb7 Add command to list available targets
6e23bb7 is described below
commit 6e23bb723392b7184cbdc255a24f38d94fa42c9d
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Wed Sep 14 16:02:08 2022 +0200
Add command to list available targets
Use 'newt target list'.
---
newt/cli/target_cmds.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/newt/cli/target_cmds.go b/newt/cli/target_cmds.go
index 525ea75..a4fa89f 100644
--- a/newt/cli/target_cmds.go
+++ b/newt/cli/target_cmds.go
@@ -40,6 +40,7 @@ import (
var amendDelete bool = false
var showAll bool = false
+var listAll bool = false
// target variables that can have values amended with the amend command.
var amendVars = []string{"aflags", "cflags", "cxxflags", "lflags", "syscfg"}
@@ -248,6 +249,39 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
}
}
+func targetListCmd(cmd *cobra.Command, args []string) {
+ TryGetProject()
+ targetNames := []string{}
+
+ for name, t := range target.GetTargets() {
+ keep := func() bool {
+ // Don't display the special unittest target; this is used
+ // internally by newt, so the user doesn't need to know about
+ // it.
+ if strings.HasSuffix(name, "/unittest") {
+ return false
+ }
+
+ // Don't show foreign targets without the `-a` option.
+ if !listAll && !t.Package().Repo().IsLocal() {
+ return false
+ }
+
+ return true
+ }
+
+ if keep() {
+ targetNames = append(targetNames, name)
+ }
+ }
+
+ sort.Strings(targetNames)
+
+ for _, name := range targetNames {
+ util.StatusMessage(util.VERBOSITY_DEFAULT, name+"\n")
+ }
+}
+
func targetCmakeCmd(cmd *cobra.Command, args []string) {
TryGetProject()
@@ -721,6 +755,20 @@ func AddTargetCommands(cmd *cobra.Command) {
targetCmd.AddCommand(showCmd)
AddTabCompleteFn(showCmd, targetList)
+ listHelpText := "List all available targets."
+ listHelpEx := " newt target list"
+
+ listCmd := &cobra.Command{
+ Use: "list",
+ Short: "List available targets",
+ Long: listHelpText,
+ Example: listHelpEx,
+ Run: targetListCmd,
+ }
+ listCmd.Flags().BoolVarP(&listAll, "all", "a", false,
+ "List all targets (including from other repos)")
+ targetCmd.AddCommand(listCmd)
+
cmakeHelpText := "Generate CMakeLists.txt for target specified " +
"by <target-name>."
cmakeHelpEx := " newt target cmake <target-name>\n"