-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: enhance usecase generator & apply in delivery
- Loading branch information
1 parent
0322cc4
commit 51a10a8
Showing
15 changed files
with
516 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/golangid/candi/candihelper" | ||
) | ||
|
||
func cliStageInputServiceName() (serviceName string) { | ||
serviceName = readInput("Please input service name:") | ||
_, err := os.Stat(serviceName) | ||
var errMessage string | ||
if strings.TrimSpace(serviceName) == "" { | ||
errMessage = "Service name cannot empty" | ||
} | ||
if !os.IsNotExist(err) { | ||
errMessage = "Folder already exists" | ||
} | ||
if errMessage != "" { | ||
fmt.Printf(RedFormat, errMessage+", try again") | ||
serviceName = cliStageInputServiceName() | ||
} | ||
return | ||
} | ||
|
||
func inputOwnerName() (ownerName string) { | ||
ownerName = readInput("Please input owner name:") | ||
var errMessage string | ||
if strings.TrimSpace(ownerName) == "" { | ||
errMessage = "Owner name cannot empty" | ||
} | ||
|
||
if errMessage != "" { | ||
fmt.Printf(RedFormat, errMessage+", try again") | ||
ownerName = inputOwnerName() | ||
} | ||
return | ||
} | ||
|
||
func cliStageInputExistingServiceName(prefixPath, cmd string) string { | ||
stageInputServiceName: | ||
serviceName := readInput(cmd) | ||
_, err := os.Stat(filepath.Join(prefixPath, serviceName)) | ||
var errMessage string | ||
if strings.TrimSpace(serviceName) == "" { | ||
errMessage = "Service name cannot empty" | ||
} | ||
if os.IsNotExist(err) { | ||
errMessage = fmt.Sprintf(`Service "%s" is not exist in "%s" directory`, serviceName, prefixPath) | ||
} | ||
if errMessage != "" { | ||
fmt.Printf(RedFormat, errMessage+", try again") | ||
goto stageInputServiceName | ||
} | ||
return serviceName | ||
} | ||
|
||
func cliStageInputModule(prefixPath, cmd string) string { | ||
stageReadInputModule: | ||
moduleName := candihelper.ToDelimited(readInput(cmd), '-') | ||
if err := validateDir(filepath.Join(prefixPath, moduleName)); err != nil { | ||
fmt.Print(err.Error()) | ||
goto stageReadInputModule | ||
} | ||
return moduleName | ||
} | ||
|
||
func cliStageInputUsecaseName(prefixPath string) string { | ||
stageAddUsecaseInputName: | ||
ucName := readInput("Please input usecase name:") | ||
dir := filepath.Join(prefixPath, "usecase", candihelper.ToDelimited(ucName, '_')+".go") | ||
if err := validateDir(dir); err == nil { | ||
fmt.Printf(RedFormat, "Usecase "+dir+" is exist, try another usecase name") | ||
goto stageAddUsecaseInputName | ||
} | ||
return ucName | ||
} | ||
|
||
func cliStageInputExistingUsecaseName(prefixPath string) string { | ||
stageAddUsecaseInputName: | ||
ucName := readInput("Please input usecase name:") | ||
dir := filepath.Join(prefixPath, "usecase", candihelper.ToDelimited(ucName, '_')+".go") | ||
if err := validateDir(dir); err != nil { | ||
fmt.Printf(RedFormat, "Usecase "+dir+" not exist") | ||
goto stageAddUsecaseInputName | ||
} | ||
return ucName | ||
} | ||
|
||
func cliStageInputExistingDelivery(prefixPath string) (deliveryHandlers []string) { | ||
wording, deliveryHandlerMap := getAllModuleHandler(prefixPath) | ||
stageSelectDeliveryHandler: | ||
cmdInput := readInput("Apply in delivery handler (separated by comma, enter for skip):\n" + wording) | ||
for _, str := range strings.Split(strings.Trim(cmdInput, ","), ",") { | ||
if delName, ok := deliveryHandlerMap[strings.TrimSpace(str)]; ok { | ||
deliveryHandlers = append(deliveryHandlers, delName) | ||
} else if str != "" { | ||
fmt.Printf(RedFormat, "Invalid option, try again") | ||
deliveryHandlers = []string{} | ||
goto stageSelectDeliveryHandler | ||
} | ||
} | ||
return deliveryHandlers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.