Skip to content

Commit

Permalink
init improvements (#25)
Browse files Browse the repository at this point in the history
* init improvements
* help fix
Fixes FSOC-110 (init with empty name and not stopping on error)
  • Loading branch information
pavelbucek authored Feb 17, 2023
1 parent 9f12c02 commit ae72320
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cmd/solution/init.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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=<solutionName> [--include-service] [--include-knowledge]
Command: fsoc solution init --name=<solutionName> [options]
Parameters:
solutionName - Name of the solution
name - Name of the solution
Options:
include-service - Flag to include sample service component
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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()

Expand Down

0 comments on commit ae72320

Please sign in to comment.