X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=cmd-projects.go;h=8c12cbf9ae57bdae9a005c971a19aa7bc25949a8;hb=2f718c72a51850f3ab1af8d93a381b594fb2c825;hp=e244e41335c692a59fa50a69364f5985ca9b684d;hpb=75416fe01aa98b53c57315a050fc58f0879a238d;p=src%2Fxds%2Fxds-cli.git diff --git a/cmd-projects.go b/cmd-projects.go index e244e41..8c12cbf 100644 --- a/cmd-projects.go +++ b/cmd-projects.go @@ -1,10 +1,28 @@ +/* + * Copyright (C) 2017-2018 "IoT.bzh" + * Author Sebastien Douheret + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + package main 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" ) @@ -33,6 +51,10 @@ 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)", @@ -45,8 +67,9 @@ func initCmdProjects(cmdDef *[]cli.Command) { Action: projectsGet, Flags: []cli.Flag{ cli.StringFlag{ - Name: "id", - Usage: "project id", + Name: "id", + Usage: "project id", + EnvVar: "XDS_PROJECT_ID", }, }, }, @@ -69,8 +92,13 @@ func initCmdProjects(cmdDef *[]cli.Command) { Action: projectsRemove, Flags: []cli.Flag{ cli.StringFlag{ - Name: "id", - Usage: "project id", + Name: "id", + Usage: "project id", + EnvVar: "XDS_PROJECT_ID", + }, + cli.BoolFlag{ + Name: "force, f", + Usage: "remove confirmation prompt before removal", }, }, }, @@ -81,8 +109,9 @@ func initCmdProjects(cmdDef *[]cli.Command) { Action: projectsSync, Flags: []cli.Flag{ cli.StringFlag{ - Name: "id", - Usage: "project id", + Name: "id", + Usage: "project id", + EnvVar: "XDS_PROJECT_ID", }, }, }, @@ -176,7 +205,11 @@ 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 } @@ -188,6 +221,12 @@ func projectsRemove(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 project id '" + id + "' [yes/No] ? ") { + return nil + } + } + if err := HTTPCli.Delete("/projects/"+id, &res); err != nil { return cli.NewExitError(err, 1) }