X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=cmd-sdks.go;h=3fc596ffd111ac8bd533cbc38dcb8f0722b0c38e;hb=5ce05ccae810f532e73350a205b979faf2603235;hp=34f5409341349550a32c8ea1b829dd699daf2fc5;hpb=75fbc67b5acf3258b604fc53ec096f46fc743270;p=src%2Fxds%2Fxds-cli.git diff --git a/cmd-sdks.go b/cmd-sdks.go index 34f5409..3fc596f 100644 --- a/cmd-sdks.go +++ b/cmd-sdks.go @@ -22,6 +22,7 @@ import ( "fmt" "os" "regexp" + "sort" "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/xaapiv1" "github.com/urfave/cli" @@ -89,6 +90,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)", + }, }, }, { @@ -200,6 +205,14 @@ func _displaySdks(sdks []xaapiv1.SDK, verbose bool, all bool, filter string) { writer.Flush() } +// Sort SDKs by ID +type _SdkByID []xaapiv1.SDK + +func (s _SdkByID) Len() int { return len(s) } +func (s _SdkByID) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s _SdkByID) Less(i, j int) bool { return s[i].ID < s[j].ID } + +// _sdksListGet Get the list of existing sdks func _sdksListGet(sdks *[]xaapiv1.SDK) error { url := XdsServerComputeURL("/sdks") if err := HTTPCli.Get(url, &sdks); err != nil { @@ -207,6 +220,8 @@ func _sdksListGet(sdks *[]xaapiv1.SDK) error { } Log.Debugf("Result of %s: %v", url, sdks) + sort.Sort(_SdkByID(*sdks)) + return nil } @@ -214,6 +229,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) @@ -281,7 +297,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" @@ -290,7 +308,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)