X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=cmd-sdks.go;h=bc9df15f2877dd40a917249eb9db9cd34f002ef1;hb=c3c015d68a6f27bdb86c594ffbb481ee68f9e0c1;hp=e140856371df3d3c5db4cc2b6f87c19ab2e02db4;hpb=36b8457bdd2e4fd222dec676988ffdf7f8e50f2f;p=src%2Fxds%2Fxds-cli.git diff --git a/cmd-sdks.go b/cmd-sdks.go index e140856..bc9df15 100644 --- a/cmd-sdks.go +++ b/cmd-sdks.go @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 "IoT.bzh" + * Copyright (C) 2017-2018 "IoT.bzh" * Author Sebastien Douheret * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import ( "os" "regexp" - "github.com/iotbzh/xds-agent/lib/xaapiv1" + "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/xaapiv1" "github.com/urfave/cli" ) @@ -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)", + }, }, }, { @@ -102,6 +106,10 @@ func initCmdSdks(cmdDef *[]cli.Command) { Usage: "sdk id to un-install", EnvVar: "XDS_SDK_ID", }, + cli.BoolFlag{ + Name: "force, f", + Usage: "remove confirmation prompt before removal", + }, }, }, { @@ -152,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 != "" { @@ -208,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) @@ -229,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.Stdout != "" { + if sdkEvt.Action != xaapiv1.SdkMgtActionInstall { + Log.Debugf("EVTSDKManagement (action %s) IGNORED", sdkEvt.Action) + return + } + + if !shortOut && sdkEvt.Stdout != "" { fmt.Printf("%s", sdkEvt.Stdout) } - if sdkEvt.Stderr != "" { + if !shortOut && sdkEvt.Stderr != "" { fmt.Fprintf(os.Stderr, "%s", sdkEvt.Stderr) } @@ -244,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) } @@ -265,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" @@ -274,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) @@ -289,6 +316,12 @@ func sdksUnInstall(ctx *cli.Context) error { return cli.NewExitError("id parameter or option must be set", 1) } + if !ctx.Bool("force") { + if !Confirm("Do you permanently remove SDK id '" + id + "' [yes/No] ? ") { + return nil + } + } + delSdk := xaapiv1.SDK{} url := XdsServerComputeURL("/sdks/" + id) if err := HTTPCli.Delete(url, &delSdk); err != nil {