X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fxds%2Fxds-cli.git;a=blobdiff_plain;f=cmd-projects.go;h=fd46d9a6277e3139466661c9d5ec8e4ee4fa64c1;hp=713e3f8899d7b3cf07eecceb401967d2d8a769df;hb=3b5e82b55433fd49cfe0cd0349756e0c2e9a9c12;hpb=f2b2c900fcc8f02a5e532794772ed5359618c3cc diff --git a/cmd-projects.go b/cmd-projects.go index 713e3f8..fd46d9a 100644 --- a/cmd-projects.go +++ b/cmd-projects.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"); @@ -22,7 +22,7 @@ import ( "fmt" "strings" - "github.com/iotbzh/xds-agent/lib/xaapiv1" + "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/xaapiv1" "github.com/urfave/cli" ) @@ -51,15 +51,19 @@ func initCmdProjects(cmdDef *[]cli.Command) { Name: "server-path, sp", Usage: "project server path (only used with pathmap type)", }, + cli.BoolFlag{ + Name: "short, s", + Usage: "short output, only print create project id (useful from scripting)", + }, cli.StringFlag{ Name: "type, t", - Usage: "project type (pathmap|pm, cloudsync|sc)", + Usage: "project type (pathmap|pm, cloudsync|cs)", }, }, }, { Name: "get", - Usage: "Get a property of a project", + Usage: "Get properties of a project", Action: projectsGet, Flags: []cli.Flag{ cli.StringFlag{ @@ -126,7 +130,7 @@ func projectsList(ctx *cli.Context) error { } func projectsGet(ctx *cli.Context) error { - id := GetID(ctx) + id := GetID(ctx, "XDS_PROJECT_ID") if id == "" { return cli.NewExitError("id parameter or option must be set", 1) } @@ -176,12 +180,12 @@ func _displayProjects(prjs []xaapiv1.ProjectConfig, verbose bool) { func projectsAdd(ctx *cli.Context) error { // Decode project type - var ptype xaapiv1.ProjectType + var pType xaapiv1.ProjectType switch strings.ToLower(ctx.String("type")) { case "pathmap", "pm": - ptype = xaapiv1.TypePathMap + pType = xaapiv1.TypePathMap case "cloudsync", "cs": - ptype = xaapiv1.TypeCloudSync + pType = xaapiv1.TypeCloudSync default: return cli.NewExitError("Unknown project type", 1) } @@ -189,7 +193,7 @@ func projectsAdd(ctx *cli.Context) error { prj := xaapiv1.ProjectConfig{ ServerID: XdsServerIDGet(), Label: ctx.String("label"), - Type: ptype, + Type: pType, ClientPath: ctx.String("path"), ServerPath: ctx.String("server-path"), } @@ -201,14 +205,18 @@ func projectsAdd(ctx *cli.Context) error { return cli.NewExitError(err, 1) } - fmt.Printf("New project '%s' (id %v) successfully created.\n", newPrj.Label, newPrj.ID) + if ctx.Bool("short") { + fmt.Println(newPrj.ID) + } else { + fmt.Printf("New project '%s' (id %v) successfully created.\n", newPrj.Label, newPrj.ID) + } return nil } func projectsRemove(ctx *cli.Context) error { var res xaapiv1.ProjectConfig - id := GetID(ctx) + id := GetID(ctx, "XDS_PROJECT_ID") if id == "" { return cli.NewExitError("id parameter or option must be set", 1) } @@ -228,7 +236,7 @@ func projectsRemove(ctx *cli.Context) error { } func projectsSync(ctx *cli.Context) error { - id := GetID(ctx) + id := GetID(ctx, "XDS_PROJECT_ID") if id == "" { return cli.NewExitError("id parameter or option must be set", 1) }