diff --git a/src/cmd/projectServiceImport.go b/src/cmd/projectServiceImport.go index 67a5cb7..eceed68 100644 --- a/src/cmd/projectServiceImport.go +++ b/src/cmd/projectServiceImport.go @@ -3,6 +3,8 @@ package cmd import ( "context" + "github.com/pkg/errors" + "github.com/zeropsio/zcli/src/cmd/scope" "github.com/zeropsio/zcli/src/cmdBuilder" "github.com/zeropsio/zcli/src/i18n" @@ -19,28 +21,20 @@ func projectServiceImportCmd() *cmdBuilder.Cmd { return cmdBuilder.NewCmd(). Use("service-import"). Short(i18n.T(i18n.CmdDescProjectServiceImport)). + Long(i18n.T(i18n.CmdDescProjectServiceImportLong)). ScopeLevel(scope.Project). Arg(serviceImportArgName). HelpFlag(i18n.T(i18n.CmdHelpProjectServiceImport)). LoggedUserRunFunc(func(ctx context.Context, cmdData *cmdBuilder.LoggedUserCmdData) error { uxBlocks := cmdData.UxBlocks - var err error - var yamlContent []byte - if cmdData.Args[serviceImportArgName][0] == "-" { - yamlContent, err = yamlReader.ReadContentFromStdin(uxBlocks) - if err != nil { - return err - } - } else { - yamlContent, err = yamlReader.ReadContent( - uxBlocks, - cmdData.Args[serviceImportArgName][0], - "./", - ) - if err != nil { - return err - } + if len(cmdData.Args[serviceImportArgName]) == 0 { + return errors.New(i18n.T(i18n.ServiceImportYamlPathMissing)) + } + + yamlContent, err := yamlReader.ReadContent(uxBlocks, cmdData.Args[serviceImportArgName][0], "./") + if err != nil { + return errors.Wrap(err, i18n.T(i18n.ServiceImportYamlReadFailed)) } importServiceResponse, err := cmdData.RestApiClient.PostServiceStackImport( @@ -51,12 +45,12 @@ func projectServiceImportCmd() *cmdBuilder.Cmd { }, ) if err != nil { - return err + return errors.Wrap(err, i18n.T(i18n.ServiceImportFailed)) } responseOutput, err := importServiceResponse.Output() if err != nil { - return err + return errors.Wrap(err, i18n.T(i18n.ServiceImportResponseParseFailed)) } var processes []uxHelpers.Process @@ -76,10 +70,10 @@ func projectServiceImportCmd() *cmdBuilder.Cmd { err = uxHelpers.ProcessCheckWithSpinner(ctx, cmdData.UxBlocks, processes) if err != nil { - return err + return errors.Wrap(err, i18n.T(i18n.ServiceImportProcessCheckFailed)) } - uxBlocks.PrintInfo(styles.InfoLine(i18n.T(i18n.ServiceImported))) + uxBlocks.PrintInfo(styles.SuccessLine(i18n.T(i18n.ServiceImported))) return nil }) diff --git a/src/i18n/en.go b/src/i18n/en.go index 1053ae3..e428367 100644 --- a/src/i18n/en.go +++ b/src/i18n/en.go @@ -329,4 +329,26 @@ more info: https://docs.zerops.io/references/cli/`, ErrorInvalidScopedProjectId: "Invalid ID of the scoped project [%s], select a different project using `zcli scope project` command.", ErrorInvalidServiceId: "Invalid service ID [%s], %s", // values: serviceId, message ErrorServiceNotFound: "Service [%s] not found", + + // Project service import + CmdDescProjectServiceImportLong: "Creates one or more Zerops services in an existing project according to the definition in the import YAML file.\n\n" + + "The YAML file should contain the service configurations including:\n" + + "- Service type and version\n" + + "- Resource allocations\n" + + "- Environment variables\n" + + "- Dependencies\n\n" + + "Example usage: zcli service-import services.yml", + ServiceImportYamlPathMissing: "YAML file path is missing. Usage: zcli service-import ", + ServiceImportYamlReadFailed: "Failed to read the YAML file. Please check if the file exists and has correct permissions", + ServiceImportFailed: "Failed to import services. Please check your YAML configuration", + ServiceImportResponseParseFailed: "Failed to parse the import response from server", + ServiceImportProcessCheckFailed: "Failed to check import processes", + ServiceImportYamlValidationFailed: "YAML validation failed. Please check your service configuration", + ServiceImportAvailableCommands: `Available commands after service import: + zcli service list - List all services in the project + zcli service start - Start a service + zcli service stop - Stop a service + zcli service log - View service logs + zcli service deploy - Deploy to service +For more information, use 'zcli --help' or visit our documentation.`, } diff --git a/src/i18n/i18n.go b/src/i18n/i18n.go index 55091c4..622719d 100644 --- a/src/i18n/i18n.go +++ b/src/i18n/i18n.go @@ -309,4 +309,14 @@ const ( ErrorInvalidScopedProjectId = "ErrorInvalidScopedProjectId" ErrorInvalidServiceId = "ErrorInvalidServiceId" ErrorServiceNotFound = "ErrorServiceNotFound" + + // Project service import + CmdDescProjectServiceImportLong = "CmdDescProjectServiceImportLong" + ServiceImportYamlPathMissing = "ServiceImportYamlPathMissing" + ServiceImportYamlReadFailed = "ServiceImportYamlReadFailed" + ServiceImportFailed = "ServiceImportFailed" + ServiceImportResponseParseFailed = "ServiceImportResponseParseFailed" + ServiceImportProcessCheckFailed = "ServiceImportProcessCheckFailed" + ServiceImportAvailableCommands = "ServiceImportAvailableCommands" + ServiceImportYamlValidationFailed = "ServiceImportYamlValidationFailed" )