"strings"
"github.com/iotbzh/xds-agent/lib/apiv1"
- common "github.com/iotbzh/xds-common/golib"
- "github.com/joho/godotenv"
"github.com/urfave/cli"
)
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",
},
func exec(ctx *cli.Context) error {
prjID := ctx.String("id")
- confFile := ctx.String("config")
rPath := ctx.String("rPath")
sdkid := ctx.String("sdkid")
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)
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}
})
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 {
}
// 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)
}