Added -s | --short option (useful from scripting)
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Tue, 23 Jan 2018 14:38:23 +0000 (15:38 +0100)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Tue, 23 Jan 2018 14:38:23 +0000 (15:38 +0100)
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
cmd-projects.go
cmd-sdks.go

index fc4bc22..8c12cbf 100644 (file)
@@ -51,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)",
@@ -201,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
 }
index 34f5409..bc9df15 100644 (file)
@@ -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)",
+                                       },
                                },
                        },
                        {
@@ -214,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)
@@ -281,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"
 
@@ -290,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)