X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=cmd-sdks.go;h=bc9df15f2877dd40a917249eb9db9cd34f002ef1;hb=2f718c72a51850f3ab1af8d93a381b594fb2c825;hp=4bc5a738a7ee3f502dfb1dcebd41c196f896fdde;hpb=7d1bcb1c9a48514e0e26246b86c8597502833b4b;p=src%2Fxds%2Fxds-cli.git diff --git a/cmd-sdks.go b/cmd-sdks.go index 4bc5a73..bc9df15 100644 --- a/cmd-sdks.go +++ b/cmd-sdks.go @@ -89,6 +89,10 @@ func initCmdSdks(cmdDef *[]cli.Command) { Name: "force", Usage: "force SDK installation when already installed", }, + cli.BoolFlag{ + Name: "short, s", + Usage: "short output, only print create sdk id (useful from scripting)", + }, }, }, { @@ -156,7 +160,9 @@ func _displaySdks(sdks []xaapiv1.SDK, verbose bool, all bool, filter string) { first := true writer := NewTableWriter() for _, s := range sdks { - if s.Status != xaapiv1.SdkStatusInstalled && !all { + if s.Status != xaapiv1.SdkStatusInstalled && + s.Status != xaapiv1.SdkStatusInstalling && + !all { continue } if filter != "" { @@ -212,6 +218,7 @@ func sdksInstall(ctx *cli.Context) error { id := GetID(ctx) file := ctx.String("file") force := ctx.Bool("force") + shortOut := ctx.Bool("short") if id == "" && file == "" { return cli.NewExitError("id or file parameter or option must be set", 1) @@ -233,13 +240,18 @@ func sdksInstall(ctx *cli.Context) error { exitChan <- exitResult{errMsg, 2} }) - IOsk.On(xaapiv1.EVTSDKInstall, func(ev xaapiv1.EventMsg) { - sdkEvt, _ := ev.DecodeSDKMsg() + IOsk.On(xaapiv1.EVTSDKManagement, func(ev xaapiv1.EventMsg) { + sdkEvt, _ := ev.DecodeSDKMgtMsg() + + if sdkEvt.Action != xaapiv1.SdkMgtActionInstall { + Log.Debugf("EVTSDKManagement (action %s) IGNORED", sdkEvt.Action) + return + } - if sdkEvt.Stdout != "" { + if !shortOut && sdkEvt.Stdout != "" { fmt.Printf("%s", sdkEvt.Stdout) } - if sdkEvt.Stderr != "" { + if !shortOut && sdkEvt.Stderr != "" { fmt.Fprintf(os.Stderr, "%s", sdkEvt.Stderr) } @@ -248,7 +260,12 @@ func sdksInstall(ctx *cli.Context) error { } }) - evReg := xaapiv1.EventRegisterArgs{Name: xaapiv1.EVTSDKInstall} + IOsk.On(xaapiv1.EVTSDKStateChange, func(ev xaapiv1.EventMsg) { + sdk, _ := ev.DecodeSDKEvent() + Log.Debugf("EVTSDKStateChange: %v", sdk) + }) + + evReg := xaapiv1.EventRegisterArgs{Name: xaapiv1.EVTAll} if err := HTTPCli.Post("/events/register", &evReg, nil); err != nil { return cli.NewExitError(err, 1) } @@ -269,7 +286,9 @@ func sdksInstall(ctx *cli.Context) error { return cli.NewExitError(err, 1) } Log.Debugf("Result of %s: %v", url, newSdk) - fmt.Printf("Installation of '%s' SDK successfully started.\n", newSdk.Name) + if !shortOut { + fmt.Printf("Installation of '%s' SDK successfully started.\n", newSdk.Name) + } // TODO: trap CTRL+C and print question: "Installation of xxx is in progress, press 'a' to abort, 'b' to continue in background or 'c' to continue installation" @@ -278,7 +297,11 @@ func sdksInstall(ctx *cli.Context) error { case res := <-exitChan: if res.code == 0 { Log.Debugln("Exit successfully") - fmt.Println("SDK ID " + newSdk.ID + " successfully installed.") + if shortOut { + fmt.Println(newSdk.ID) + } else { + fmt.Println("SDK ID " + newSdk.ID + " successfully installed.") + } } if res.error != "" { Log.Debugln("Exit with ERROR: ", res.error)