Check go version because xds-common request go > v1.8.1
[src/xds/xds-cli.git] / cmd-exec.go
index 612851f..b8d88b5 100644 (file)
@@ -5,9 +5,7 @@ import (
        "os"
        "strings"
 
-       "github.com/iotbzh/xds-agent/lib/apiv1"
-       common "github.com/iotbzh/xds-common/golib"
-       "github.com/joho/godotenv"
+       "github.com/iotbzh/xds-agent/lib/xaapiv1"
        "github.com/urfave/cli"
 )
 
@@ -23,12 +21,12 @@ func initCmdExec(cmdDef *[]cli.Command) {
                                Usage:  "project ID you want to build (mandatory variable)",
                        },
                        cli.StringFlag{
-                               Name:   "rpath",
+                               Name:   "rpath, p",
                                EnvVar: "XDS_RPATH",
                                Usage:  "relative path into project",
                        },
                        cli.StringFlag{
-                               Name:   "sdkid",
+                               Name:   "sdkid, sdk",
                                EnvVar: "XDS_SDK_ID",
                                Usage:  "Cross Sdk ID to use to build project",
                        },
@@ -38,7 +36,6 @@ func initCmdExec(cmdDef *[]cli.Command) {
 
 func exec(ctx *cli.Context) error {
        prjID := ctx.String("id")
-       confFile := ctx.String("config")
        rPath := ctx.String("rPath")
        sdkid := ctx.String("sdkid")
 
@@ -47,29 +44,12 @@ func exec(ctx *cli.Context) error {
                return cli.NewExitError("project id must be set (see --id option)", 1)
        }
 
-       // Load config file if requested
-       envMap := make(map[string]string)
-       if confFile != "" {
-               if !common.Exists(confFile) {
-                       exitError(1, "Error env config file not found")
-               }
-               // Load config file variables that will overwrite env variables
-               err := godotenv.Overload(confFile)
-               if err != nil {
-                       exitError(1, "Error loading env config file "+confFile)
-               }
-               envMap, err = godotenv.Read(confFile)
-               if err != nil {
-                       exitError(1, "Error reading env config file "+confFile)
-               }
-       }
-
        argsCommand := make([]string, len(ctx.Args()))
        copy(argsCommand, ctx.Args())
        Log.Infof("Execute: /exec %v", argsCommand)
 
        // Log useful info for debugging
-       ver := apiv1.XDSVersion{}
+       ver := xaapiv1.XDSVersion{}
        XdsVersionGet(&ver)
        Log.Infof("XDS version: %v", ver)
 
@@ -81,6 +61,7 @@ func exec(ctx *cli.Context) error {
        exitChan := make(chan exitResult, 1)
 
        IOsk.On("disconnection", func(err error) {
+               Log.Debugf("WS disconnection event with err: %v\n", err)
                exitChan <- exitResult{err, 2}
        })
 
@@ -97,16 +78,25 @@ func exec(ctx *cli.Context) error {
                }
        }
 
-       IOsk.On(apiv1.ExecOutEvent, func(ev apiv1.ExecOutMsg) {
+       IOsk.On(xaapiv1.ExecOutEvent, func(ev xaapiv1.ExecOutMsg) {
                outFunc(ev.Timestamp, ev.Stdout, ev.Stderr)
        })
 
-       IOsk.On(apiv1.ExecExitEvent, func(ev apiv1.ExecExitMsg) {
+       IOsk.On(xaapiv1.ExecExitEvent, func(ev xaapiv1.ExecExitMsg) {
                exitChan <- exitResult{ev.Error, ev.Code}
        })
 
+       IOsk.On(xaapiv1.EVTProjectChange, func(ev xaapiv1.EventMsg) {
+               prj, _ := ev.DecodeProjectConfig()
+               Log.Infof("Event %v (%v): %v", ev.Type, ev.Time, prj)
+       })
+       evReg := xaapiv1.EventRegisterArgs{Name: xaapiv1.EVTProjectChange}
+       if err := HTTPCli.Post("/events/register", &evReg, nil); err != nil {
+               return cli.NewExitError(err, 1)
+       }
+
        // Retrieve the project definition
-       prj := apiv1.ProjectConfig{}
+       prj := xaapiv1.ProjectConfig{}
        if err := HTTPCli.Get("/projects/"+prjID, &prj); err != nil {
                return cli.NewExitError(err, 1)
        }
@@ -128,14 +118,14 @@ func exec(ctx *cli.Context) error {
        }
 
        // Build env
-       Log.Debugf("Command env: %v", envMap)
+       Log.Debugf("Command env: %v", EnvConfFileMap)
        env := []string{}
-       for k, v := range envMap {
+       for k, v := range EnvConfFileMap {
                env = append(env, k+"="+v)
        }
 
        // Send build command
-       args := apiv1.ExecArgs{
+       args := xaapiv1.ExecArgs{
                ID:         prjID,
                SdkID:      sdkid,
                Cmd:        strings.Trim(argsCommand[0], " "),