Code Review
/
src
/
xds
/
xds-cli.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Fix expired link.
[src/xds/xds-cli.git]
/
cmd-projects.go
diff --git
a/cmd-projects.go
b/cmd-projects.go
index
13a7126
..
fd46d9a
100644
(file)
--- 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 <sebastien@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Author Sebastien Douheret <sebastien@iot.bzh>
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@
-22,7
+22,7
@@
import (
"fmt"
"strings"
"fmt"
"strings"
- "g
ithub.com/iotbzh/xds-agen
t/lib/xaapiv1"
+ "g
errit.automotivelinux.org/gerrit/src/xds/xds-agent.gi
t/lib/xaapiv1"
"github.com/urfave/cli"
)
"github.com/urfave/cli"
)
@@
-51,20
+51,25
@@
func initCmdProjects(cmdDef *[]cli.Command) {
Name: "server-path, sp",
Usage: "project server path (only used with pathmap type)",
},
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",
cli.StringFlag{
Name: "type, t",
- Usage: "project type (pathmap|pm, cloudsync|
sc
)",
+ Usage: "project type (pathmap|pm, cloudsync|
cs
)",
},
},
},
{
Name: "get",
},
},
},
{
Name: "get",
- Usage: "Get
a property
of a project",
+ Usage: "Get
properties
of a project",
Action: projectsGet,
Flags: []cli.Flag{
cli.StringFlag{
Action: projectsGet,
Flags: []cli.Flag{
cli.StringFlag{
- Name: "id",
- Usage: "project id",
+ Name: "id",
+ Usage: "project id",
+ EnvVar: "XDS_PROJECT_ID",
},
},
},
},
},
},
@@
-87,8
+92,13
@@
func initCmdProjects(cmdDef *[]cli.Command) {
Action: projectsRemove,
Flags: []cli.Flag{
cli.StringFlag{
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",
},
},
},
},
},
},
@@
-99,8
+109,9
@@
func initCmdProjects(cmdDef *[]cli.Command) {
Action: projectsSync,
Flags: []cli.Flag{
cli.StringFlag{
Action: projectsSync,
Flags: []cli.Flag{
cli.StringFlag{
- Name: "id",
- Usage: "project id",
+ Name: "id",
+ Usage: "project id",
+ EnvVar: "XDS_PROJECT_ID",
},
},
},
},
},
},
@@
-119,7
+130,7
@@
func projectsList(ctx *cli.Context) error {
}
func projectsGet(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)
}
if id == "" {
return cli.NewExitError("id parameter or option must be set", 1)
}
@@
-169,12
+180,12
@@
func _displayProjects(prjs []xaapiv1.ProjectConfig, verbose bool) {
func projectsAdd(ctx *cli.Context) error {
// Decode project type
func projectsAdd(ctx *cli.Context) error {
// Decode project type
- var p
t
ype xaapiv1.ProjectType
+ var p
T
ype xaapiv1.ProjectType
switch strings.ToLower(ctx.String("type")) {
case "pathmap", "pm":
switch strings.ToLower(ctx.String("type")) {
case "pathmap", "pm":
- p
t
ype = xaapiv1.TypePathMap
+ p
T
ype = xaapiv1.TypePathMap
case "cloudsync", "cs":
case "cloudsync", "cs":
- p
t
ype = xaapiv1.TypeCloudSync
+ p
T
ype = xaapiv1.TypeCloudSync
default:
return cli.NewExitError("Unknown project type", 1)
}
default:
return cli.NewExitError("Unknown project type", 1)
}
@@
-182,7
+193,7
@@
func projectsAdd(ctx *cli.Context) error {
prj := xaapiv1.ProjectConfig{
ServerID: XdsServerIDGet(),
Label: ctx.String("label"),
prj := xaapiv1.ProjectConfig{
ServerID: XdsServerIDGet(),
Label: ctx.String("label"),
- Type: p
t
ype,
+ Type: p
T
ype,
ClientPath: ctx.String("path"),
ServerPath: ctx.String("server-path"),
}
ClientPath: ctx.String("path"),
ServerPath: ctx.String("server-path"),
}
@@
-194,18
+205,28
@@
func projectsAdd(ctx *cli.Context) error {
return cli.NewExitError(err, 1)
}
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
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)
}
if id == "" {
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)
}
if err := HTTPCli.Delete("/projects/"+id, &res); err != nil {
return cli.NewExitError(err, 1)
}
@@
-215,7
+236,7
@@
func projectsRemove(ctx *cli.Context) error {
}
func projectsSync(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)
}
if id == "" {
return cli.NewExitError("id parameter or option must be set", 1)
}