Skip to content

Commit

Permalink
newt/cli: Add target info command
Browse files Browse the repository at this point in the history
This command prints all target's packages that contain app.flags
field and it's values. In the future this command
might be extended to show other miscellaneous info about
specified target.
  • Loading branch information
m-gorecki committed Feb 1, 2024
1 parent 9c9dd5c commit 92bffd5
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions newt/cli/target_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"bytes"
"fmt"
"io/ioutil"
"mynewt.apache.org/newt/newt/ycfg"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -249,6 +250,50 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
}
}

func printCflags(appCflags []ycfg.YCfgEntry) {
for _, f := range appCflags {
if itfVals, ok := f.Value.([]interface{}); ok {
for _, itfVal := range itfVals {
if strVal, ok := itfVal.(string); ok {
fmt.Println(strVal)
}
}
}
}
}

func targetInfoCmd(cmd *cobra.Command, args []string) {
if len(args) < 1 {
NewtUsage(cmd,
util.NewNewtError("Must specify target name"))
}

TryGetProject()

b, err := TargetBuilderForTargetOrUnittest(args[0])
if err != nil {
NewtUsage(cmd, err)
}

if err := b.PrepBuild(); err != nil {
NewtUsage(nil, err)
}

fmt.Println("Packages containing app.cflags:")

for _, rpkg := range b.AppBuilder.SortedRpkgs() {
appCflags, err := rpkg.Lpkg.PkgY.Get("app.cflags", nil)
if err != nil {
NewtUsage(nil, err)
}
if appCflags != nil {
fmt.Println(rpkg.Lpkg.Name())
printCflags(appCflags)
fmt.Println("")
}
}
}

func targetListCmd(cmd *cobra.Command, args []string) {
TryGetProject()
targetNames := []string{}
Expand Down Expand Up @@ -937,6 +982,21 @@ func AddTargetCommands(cmd *cobra.Command) {
return append(targetList(), unittestList()...)
})

infoHelpText := "Shows which packages contain app cflags in the target specified " +
"by <target-name>."
infoHelpEx := " newt target info <target-name>\n"
infoHelpEx += " newt target info my_target1"

infoCmd := &cobra.Command{
Use: "info",
Short: "Show packages with global cflags",
Long: infoHelpText,
Example: infoHelpEx,
Run: targetInfoCmd,
}
targetCmd.AddCommand(infoCmd)
AddTabCompleteFn(infoCmd, targetList)

for _, cmd := range targetCfgCmdAll() {
targetCmd.AddCommand(cmd)
}
Expand Down

0 comments on commit 92bffd5

Please sign in to comment.