Added config and install scripts
[src/xds/xds-cli.git] / cmd-exec.go
index 612851f..c02496b 100644 (file)
@@ -6,8 +6,6 @@ import (
        "strings"
 
        "github.com/iotbzh/xds-agent/lib/apiv1"
-       common "github.com/iotbzh/xds-common/golib"
-       "github.com/joho/godotenv"
        "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,23 +44,6 @@ 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)
@@ -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}
        })
 
@@ -105,6 +86,15 @@ func exec(ctx *cli.Context) error {
                exitChan <- exitResult{ev.Error, ev.Code}
        })
 
+       IOsk.On(apiv1.EVTProjectChange, func(ev apiv1.EventMsg) {
+               prj, _ := ev.DecodeProjectConfig()
+               Log.Infof("Event %v (%v): %v", ev.Type, ev.Time, prj)
+       })
+       evReg := apiv1.EventRegisterArgs{Name: apiv1.EVTProjectChange}
+       if err := HTTPCli.Post("/events/register", &evReg, nil); err != nil {
+               return cli.NewExitError(err, 1)
+       }
+
        // Retrieve the project definition
        prj := apiv1.ProjectConfig{}
        if err := HTTPCli.Get("/projects/"+prjID, &prj); err != nil {
@@ -128,9 +118,9 @@ 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)
        }