diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1f16e573..958bf844 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,3 @@ ## Contributing Guide -work in progress \ No newline at end of file +work-in-progress diff --git a/src/archiveClient/handler_findFilesByRules_test.go b/src/archiveClient/handler_findFilesByRules_test.go index f66c29e9..b4e35915 100644 --- a/src/archiveClient/handler_findFilesByRules_test.go +++ b/src/archiveClient/handler_findFilesByRules_test.go @@ -1,4 +1,5 @@ //go:build exclude + package archiveClient import ( diff --git a/src/archiveClient/handler_findGitFiles_test.go b/src/archiveClient/handler_findGitFiles_test.go index eba2eca0..0ed05974 100644 --- a/src/archiveClient/handler_findGitFiles_test.go +++ b/src/archiveClient/handler_findGitFiles_test.go @@ -1,4 +1,5 @@ //go:build exclude + package archiveClient import ( diff --git a/src/cmd/projectImport.go b/src/cmd/projectImport.go index 7fdcd1bd..caadde8b 100644 --- a/src/cmd/projectImport.go +++ b/src/cmd/projectImport.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "path/filepath" "github.com/zeropsio/zcli/src/cmdBuilder" "github.com/zeropsio/zcli/src/entity/repository" @@ -14,16 +15,16 @@ import ( "github.com/zeropsio/zerops-go/types/uuid" ) -const projectImportArgName = "importYamlPath" +const defaultYamlFilePattern = "*import.yml" func projectImportCmd() *cmdBuilder.Cmd { return cmdBuilder.NewCmd(). Use("project-import"). + Aliases("import"). Short(i18n.T(i18n.CmdDescProjectImport)). Long(i18n.T(i18n.CmdDescProjectImportLong)). - Arg(projectImportArgName). StringFlag("orgId", "", i18n.T(i18n.OrgIdFlag)). - StringFlag("workingDie", "./", i18n.T(i18n.BuildWorkingDir)). + StringFlag("workingDir", "./", i18n.T(i18n.BuildWorkingDir)). HelpFlag(i18n.T(i18n.CmdHelpProjectImport)). LoggedUserRunFunc(func(ctx context.Context, cmdData *cmdBuilder.LoggedUserCmdData) error { uxBlocks := cmdData.UxBlocks @@ -33,11 +34,18 @@ func projectImportCmd() *cmdBuilder.Cmd { return err } - yamlContent, err := yamlReader.ReadContent( - uxBlocks, - cmdData.Args[projectImportArgName][0], - cmdData.Params.GetString("workingDir"), - ) + workingDir := cmdData.Params.GetString("workingDir") + + yamlFiles, err := filepath.Glob(filepath.Join(workingDir, defaultYamlFilePattern)) + if err != nil || len(yamlFiles) == 0 { + uxBlocks.PrintError(styles.ErrorLine(i18n.T(i18n.NoYamlFound))) + return err + } + + yamlFilePath := yamlFiles[0] + uxBlocks.PrintInfo(styles.InfoLine("Using YAML file: " + yamlFilePath)) + + yamlContent, err := yamlReader.ReadContent(uxBlocks, yamlFilePath, workingDir) if err != nil { return err } @@ -50,16 +58,18 @@ func projectImportCmd() *cmdBuilder.Cmd { }, ) if err != nil { + uxBlocks.PrintError(styles.ErrorLine(i18n.T(i18n.ProjectImportFailed))) return err } - responseOutput, err := importProjectResponse.Output() + projectOutput, err := importProjectResponse.Output() if err != nil { + uxBlocks.PrintError(styles.ErrorLine(i18n.T(i18n.ProjectImportFailed))) return err } var processes []uxHelpers.Process - for _, service := range responseOutput.ServiceStacks { + for _, service := range projectOutput.ServiceStacks { for _, process := range service.Processes { processes = append(processes, uxHelpers.Process{ F: uxHelpers.CheckZeropsProcess(process.Id, cmdData.RestApiClient), @@ -70,7 +80,7 @@ func projectImportCmd() *cmdBuilder.Cmd { } } - uxBlocks.PrintInfo(styles.InfoLine(i18n.T(i18n.ServiceCount, len(responseOutput.ServiceStacks)))) + uxBlocks.PrintInfo(styles.InfoLine(i18n.T(i18n.ServiceCount, len(projectOutput.ServiceStacks)))) uxBlocks.PrintInfo(styles.InfoLine(i18n.T(i18n.QueuedProcesses, len(processes)))) uxBlocks.PrintInfo(styles.InfoLine(i18n.T(i18n.CoreServices))) @@ -80,7 +90,6 @@ func projectImportCmd() *cmdBuilder.Cmd { } uxBlocks.PrintInfo(styles.InfoLine(i18n.T(i18n.ProjectImported))) - return nil }) } diff --git a/src/cmdBuilder/buildCobraCmd.go b/src/cmdBuilder/buildCobraCmd.go index 99be8208..4dedee22 100644 --- a/src/cmdBuilder/buildCobraCmd.go +++ b/src/cmdBuilder/buildCobraCmd.go @@ -20,6 +20,7 @@ func buildCobraCmd( Short: cmd.short, SilenceUsage: cmd.silenceUsage, SilenceErrors: cmd.silenceError, + Aliases: cmd.aliases, } if cmd.helpTemplate != "" { diff --git a/src/cmdBuilder/cmd.go b/src/cmdBuilder/cmd.go index 4d4a7f60..008a0fa0 100644 --- a/src/cmdBuilder/cmd.go +++ b/src/cmdBuilder/cmd.go @@ -14,6 +14,7 @@ type ScopeLevel interface { type Cmd struct { use string + aliases []string short string long string helpTemplate string @@ -60,6 +61,11 @@ func (cmd *Cmd) Use(use string) *Cmd { return cmd } +func (cmd *Cmd) Aliases(aliases ...string) *Cmd { + cmd.aliases = aliases + return cmd +} + func (cmd *Cmd) SetHelpTemplate(template string) *Cmd { cmd.helpTemplate = template return cmd diff --git a/src/i18n/en.go b/src/i18n/en.go index 957cde63..a2cfb9aa 100644 --- a/src/i18n/en.go +++ b/src/i18n/en.go @@ -68,9 +68,11 @@ and your %s.`, // project import CmdHelpProjectImport: "the project import command.", - CmdDescProjectImport: "Creates a new project with one or more services.", + CmdDescProjectImport: "Initializes a new project with one or more services with project-import.yaml.", CmdDescProjectImportLong: "Creates a new project with one or more services according to the definition in the import YAML file.", - ProjectImported: "project imported", + ProjectImported: "Project is successfully imported", + NoYamlFound: "No import yaml file detected in your directory. For more information, please visit https://docs.zerops.io/references/import/.", + ProjectImportFailed: "Failed while importing, seems like there's an issue try reaching out at https://discord.com/invite/WDvCZ54", // project service import CmdHelpProjectServiceImport: "the project service import command.", @@ -258,7 +260,7 @@ at https://docs.zerops.io/references/cli for further details.`, // import ImportYamlOk: "Yaml file was checked", - ImportYamlEmpty: "Config file import yaml is empty", + ImportYamlEmpty: "The config import yaml file is empty. For more information, please visit https://docs.zerops.io/references/import/.", ImportYamlTooLarge: "Max. size of import yaml is 100 KB", ImportYamlFound: "Import yaml found", ImportYamlNotFound: "Import yaml not found", diff --git a/src/i18n/i18n.go b/src/i18n/i18n.go index 60e8a88a..4c366fd7 100644 --- a/src/i18n/i18n.go +++ b/src/i18n/i18n.go @@ -71,6 +71,8 @@ const ( CmdDescProjectImport = "CmdDescProjectImport" CmdDescProjectImportLong = "CmdDescProjectImportLong" ProjectImported = "ProjectImported" + NoYamlFound = "NoYamlFound" + ProjectImportFailed = "ProjectImportFailed" // project service import CmdHelpProjectServiceImport = "CmdHelpProjectServiceImport"