Skip to content

Commit 5c7b958

Browse files
committed
newt/cli: Add target env command
This command prints full paths to target binaries in form of environmental variables definitions like this: ELF_PATH=<path_to_elf> IMG_PATH=<path_to_img> HEX_PATH=<path_to_hex>
1 parent 6affd38 commit 5c7b958

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

newt/cli/target_cmds.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"sort"
2929
"strings"
3030

31+
log "github.com/sirupsen/logrus"
3132
"github.com/spf13/cobra"
3233

3334
"mynewt.apache.org/newt/newt/builder"
@@ -252,6 +253,34 @@ func targetShowCmd(cmd *cobra.Command, args []string) {
252253
}
253254
}
254255

256+
func targetEnvCmd(cmd *cobra.Command, args []string) {
257+
if len(args) < 1 {
258+
NewtUsage(cmd, util.NewNewtError("Must specify target"))
259+
}
260+
261+
TryGetProject()
262+
263+
t := ResolveTarget(args[0])
264+
if t == nil {
265+
NewtUsage(cmd, util.NewNewtError("Invalid target name: " + args[0]))
266+
}
267+
268+
b, err := builder.NewTargetBuilder(t)
269+
if err != nil {
270+
NewtUsage(nil, err)
271+
}
272+
273+
log.SetLevel(log.ErrorLevel)
274+
275+
if err := b.PrepBuild(); err != nil {
276+
NewtUsage(nil, err)
277+
}
278+
279+
fmt.Printf("ELF_PATH=" + b.AppBuilder.AppElfPath() + "\n")
280+
fmt.Printf("IMG_PATH=" + b.AppBuilder.AppImgPath() + "\n")
281+
fmt.Printf("HEX_PATH=" + b.AppBuilder.AppHexPath() + "\n")
282+
}
283+
255284
func printCflags(appCflags []ycfg.YCfgEntry) {
256285
for _, f := range appCflags {
257286
if itfVals, ok := f.Value.([]interface{}); ok {
@@ -802,6 +831,21 @@ func AddTargetCommands(cmd *cobra.Command) {
802831
targetCmd.AddCommand(showCmd)
803832
AddTabCompleteFn(showCmd, targetList)
804833

834+
envHelpText := "Show environment variables pointing to the binaries produced for the given " +
835+
"<target-name>."
836+
envHelpEx := " newt target env <target-name>\n"
837+
envHelpEx += " newt target env my_target1"
838+
839+
envCmd := &cobra.Command{
840+
Use: "env",
841+
Short: "Print target environmental variables",
842+
Long: envHelpText,
843+
Example: envHelpEx,
844+
Run: targetEnvCmd,
845+
}
846+
targetCmd.AddCommand(envCmd)
847+
AddTabCompleteFn(envCmd, targetList)
848+
805849
listHelpText := "List all available targets."
806850
listHelpEx := " newt target list"
807851

0 commit comments

Comments
 (0)