From ae723200f18648b1652d6e8066bec5e59c0624ba Mon Sep 17 00:00:00 2001 From: Pavel Bucek Date: Fri, 17 Feb 2023 05:42:21 +0100 Subject: [PATCH] init improvements (#25) * init improvements * help fix Fixes FSOC-110 (init with empty name and not stopping on error) --- cmd/solution/init.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/solution/init.go b/cmd/solution/init.go index 3d7f9c0b..568269d2 100644 --- a/cmd/solution/init.go +++ b/cmd/solution/init.go @@ -1,4 +1,4 @@ -// Copyright 2022 Cisco Systems, Inc. +// Copyright 2023 Cisco Systems, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,12 +30,12 @@ import ( var solutionInitCmd = &cobra.Command{ Use: "init", Short: "Creates a new solution package", - Long: `This command list all the solutions that are deployed in the current tenant specified in the profile. + Long: `This command creates a skeleton of a new solution by given name. - Command: fsoc solution init --name= [--include-service] [--include-knowledge] + Command: fsoc solution init --name= [options] Parameters: - solutionName - Name of the solution + name - Name of the solution Options: include-service - Flag to include sample service component @@ -68,10 +68,17 @@ func generateSolutionPackage(cmd *cobra.Command, args []string) { solutionName, _ := cmd.Flags().GetString("name") solutionName = strings.ToLower(solutionName) + + if len(solutionName) == 0 { + log.Errorf("Parameter \"name\" is required") + return + } + output.PrintCmdStatus(cmd, fmt.Sprintf("Preparing the %s solution package folder structure... \n", solutionName)) if err := os.Mkdir(solutionName, os.ModePerm); err != nil { log.Errorf("Solution init failed - %v", err.Error()) + return } manifest := createInitialSolutionManifest(solutionName) @@ -134,6 +141,7 @@ func createSolutionManifestFile(folderName string, manifest *Manifest) { if err != nil { log.Errorf("Failed to create manifest.json %v", err.Error()) + return } manifestJson, _ := json.Marshal(manifest) @@ -182,6 +190,7 @@ func createComponentFile(compDef any, folderName string, fileName string) { if _, err := os.Stat(folderName); os.IsNotExist(err) { if err := os.Mkdir(folderName, os.ModePerm); err != nil { log.Errorf("Create solution component file failed - %v", err.Error()) + return } } @@ -190,6 +199,7 @@ func createComponentFile(compDef any, folderName string, fileName string) { svcFile, err := os.Create(filepath) if err != nil { log.Errorf("Create solution component file failed - %v", err.Error()) + return } defer svcFile.Close()