From 9162e7a082c4c7565cad10c5349a967f4d5d267d Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Tue, 5 Sep 2023 18:06:27 -0300 Subject: [PATCH 01/10] fix: better user experience messages --- messages/build/errors.go | 1 + messages/general/messages.go | 1 + messages/root/messages.go | 4 ++-- pkg/cmd/build/run.go | 3 ++- pkg/cmd/deploy/deploy_test.go | 2 +- pkg/cmd/link/link.go | 4 ++-- pkg/cmd/root/help.go | 31 +++++++++++++++++-------------- pkg/cmd/root/root.go | 9 +++++++++ utils/errors.go | 2 +- 9 files changed, 36 insertions(+), 21 deletions(-) diff --git a/messages/build/errors.go b/messages/build/errors.go index 9e9a74f9d..209a2b234 100644 --- a/messages/build/errors.go +++ b/messages/build/errors.go @@ -3,6 +3,7 @@ package build import "errors" var ( + ErrorBuilding = errors.New("Failed to build your project. Make sure you have initialized your project by running the init or link commands. For more information run 'azion build --debug' or contact Azion's support") ErrorVulcanExecute = errors.New("Error executing Vulcan: %s") EdgeApplicationsOutputErr = errors.New("This output-ctrl option is not available. Read the readme files found in the repository https://github.com/aziontech/azioncli-template and try again") ErrFailedToRunBuildCommand = errors.New("Failed to run the build command. Verify if the command is correct and check the output above for more details. Run the 'azion build' command again or contact Azion's support") diff --git a/messages/general/messages.go b/messages/general/messages.go index 2e78ad092..edd4fdb88 100644 --- a/messages/general/messages.go +++ b/messages/general/messages.go @@ -8,4 +8,5 @@ var ( ApiListFlagPage = "Returns a page of the list according to its number" ApiListFlagPageSize = "Defines how many items should be returned per page" ApiListFlagFilter = "Filters items by their name" + CliVersion = "Azion CLI %s" ) diff --git a/messages/root/messages.go b/messages/root/messages.go index 6abc07af4..4ccc18a3b 100644 --- a/messages/root/messages.go +++ b/messages/root/messages.go @@ -1,8 +1,8 @@ package root var ( - RootUsage = "azion [flags]\n azion [flags]\n\t" - RootDescription = "Azion CLI %s" + RootUsage = "azion [flags]" + RootDescription = "The Azion Command Line Interface is a unified tool to manage your Azion projects and resources" RootHelpFlag = "Displays more information about the Azion CLI" RootDoNotUpdate = "Do not receive update notification" RootLogDebug = "Displays log at a debug level" diff --git a/pkg/cmd/build/run.go b/pkg/cmd/build/run.go index 0e8062ad8..15f733f3d 100644 --- a/pkg/cmd/build/run.go +++ b/pkg/cmd/build/run.go @@ -26,7 +26,8 @@ func RunBuildCmdLine(cmd *BuildCmd) error { conf, err := cmd.GetAzionJsonContent() if err != nil { - return err + logger.Debug("Error while building your project", zap.Error(err)) + return msg.ErrorBuilding } if Preset != "" { diff --git a/pkg/cmd/deploy/deploy_test.go b/pkg/cmd/deploy/deploy_test.go index d81a37a42..b8e53a2f8 100644 --- a/pkg/cmd/deploy/deploy_test.go +++ b/pkg/cmd/deploy/deploy_test.go @@ -58,7 +58,7 @@ func TestDeployCmd(t *testing.T) { err := cmd.Execute() - require.EqualError(t, err, "Failed to open the azion.json file. The file doesn't exist, is corrupted, or has an invalid JSON format. Verify if the file format is JSON or fix its content according to the JSON format specification at https://www.json.org/json-en.html") + require.EqualError(t, err, "Failed to build your project. Make sure you have initialized your project by running the init or link commands. For more information run 'azion build --debug' or contact Azion's support") }) t.Run("failed to create application", func(t *testing.T) { diff --git a/pkg/cmd/link/link.go b/pkg/cmd/link/link.go index 55c842384..b01199e4b 100644 --- a/pkg/cmd/link/link.go +++ b/pkg/cmd/link/link.go @@ -186,12 +186,12 @@ func (cmd *LinkCmd) run(info *LinkInfo, options *contracts.AzionApplicationOptio return err } if shouldDev { - shouldYarn, err := cmd.ShouldDevDeploy(info, "Do you want to install project dependencies? This may be required to start local development server") + shouldDeps, err := cmd.ShouldDevDeploy(info, "Do you want to install project dependencies? This may be required to start local development server") if err != err { return err } - if shouldYarn { + if shouldDeps { err = yarnInstall(cmd) if err != nil { logger.Debug("Failed to install project dependencies") diff --git a/pkg/cmd/root/help.go b/pkg/cmd/root/help.go index 3d7c763d3..53a318871 100644 --- a/pkg/cmd/root/help.go +++ b/pkg/cmd/root/help.go @@ -5,6 +5,8 @@ import ( "fmt" "strings" + msg "github.com/aziontech/azion-cli/messages/general" + "github.com/aziontech/azion-cli/pkg/cmd/version" "github.com/aziontech/azion-cli/pkg/cmdutil" "github.com/aziontech/azion-cli/pkg/text" "github.com/fatih/color" @@ -51,11 +53,6 @@ func rootHelpFunc(f *cmdutil.Factory, command *cobra.Command, args []string) { return } - // in case root command is run only with --token flag, we only show the token being saved - if command.Flags().Changed("token") { - return - } - var ( baseCommands []string subcmdCommands []string @@ -98,16 +95,22 @@ func rootHelpFunc(f *cmdutil.Factory, command *cobra.Command, args []string) { longText = command.Short } + styleTitle := color.Bold + styleBody := color.FgHiWhite + helpEntries := []helpEntry{} + + helpEntries = append(helpEntries, helpEntry{"", color.New(color.Bold).Sprint(fmt.Sprintf(msg.CliVersion, version.BinVersion))}) + if longText != "" { - helpEntries = append(helpEntries, helpEntry{"", longText}) + helpEntries = append(helpEntries, helpEntry{ + Title: color.New(styleTitle).Sprint("DESCRIPTION"), + Body: color.New(styleBody).Sprint(longText), + }) } - styleTitle := color.Bold - styleBody := color.FgHiWhite - helpEntries = append(helpEntries, helpEntry{ - Title: color.New(styleTitle).Sprint("USAGE"), + Title: color.New(styleTitle).Sprint("SYNOPSIS"), Body: color.New(styleBody).Sprint(command.UseLine()), }) @@ -120,14 +123,14 @@ func rootHelpFunc(f *cmdutil.Factory, command *cobra.Command, args []string) { if len(baseCommands) > 0 { helpEntries = append(helpEntries, helpEntry{ - Title: color.New(styleTitle).Sprint("COMMANDS"), + Title: color.New(styleTitle).Sprint("AVAILABLE COMMANDS"), Body: color.New(styleBody).Sprint(strings.Join(baseCommands, "\n")), }) } if len(subcmdCommands) > 0 { helpEntries = append(helpEntries, helpEntry{ - Title: color.New(styleTitle).Sprint("SUBCOMMANDS"), + Title: color.New(styleTitle).Sprint("AVAILABLE SUBCOMMANDS"), Body: color.New(styleBody).Sprint(strings.Join(subcmdCommands, "\n")), }) } @@ -135,7 +138,7 @@ func rootHelpFunc(f *cmdutil.Factory, command *cobra.Command, args []string) { flagUsages := command.LocalFlags().FlagUsages() if flagUsages != "" { helpEntries = append(helpEntries, helpEntry{ - Title: color.New(styleTitle).Sprint("FLAGS"), + Title: color.New(styleTitle).Sprint("LOCAL OPTIONS"), Body: color.New(styleBody).Sprint(dedent(flagUsages)), }) } @@ -143,7 +146,7 @@ func rootHelpFunc(f *cmdutil.Factory, command *cobra.Command, args []string) { inheritedFlagUsages := command.InheritedFlags().FlagUsages() if inheritedFlagUsages != "" { helpEntries = append(helpEntries, helpEntry{ - Title: color.New(styleTitle).Sprint("INHERITED FLAGS"), + Title: color.New(styleTitle).Sprint("GLOBAL OPTIONS"), Body: color.New(styleBody).Sprint(dedent(inheritedFlagUsages)), }) } diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index 3831271dd..fe3bed441 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -5,8 +5,10 @@ import ( "net/http" "time" + "github.com/MakeNowJust/heredoc" msg "github.com/aziontech/azion-cli/messages/root" buildCmd "github.com/aziontech/azion-cli/pkg/cmd/build" + "github.com/aziontech/azion-cli/pkg/cmd/completion" deploycmd "github.com/aziontech/azion-cli/pkg/cmd/deploy" devcmd "github.com/aziontech/azion-cli/pkg/cmd/dev" initcmd "github.com/aziontech/azion-cli/pkg/cmd/init" @@ -31,6 +33,7 @@ var ( func NewRootCmd(f *cmdutil.Factory) *cobra.Command { rootCmd := &cobra.Command{ Use: msg.RootUsage, + Long: msg.RootDescription, Short: color.New(color.Bold).Sprint(fmt.Sprintf(msg.RootDescription, version.BinVersion)), Version: version.BinVersion, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { @@ -44,6 +47,11 @@ func NewRootCmd(f *cmdutil.Factory) *cobra.Command { } return nil }, + Example: heredoc.Doc(` + $ azion + $ azion -t azionb43a9554776zeg05b11cb1declkbabcc9la + $ azion -h + `), RunE: func(cmd *cobra.Command, args []string) error { return cmd.Help() }, @@ -79,6 +87,7 @@ func NewRootCmd(f *cmdutil.Factory) *cobra.Command { rootCmd.AddCommand(devcmd.NewCmd(f)) rootCmd.AddCommand(linkcmd.NewCmd(f)) rootCmd.AddCommand(personal_token.NewCmd(f)) + rootCmd.AddCommand(completion.NewCmd(f)) return rootCmd } diff --git a/utils/errors.go b/utils/errors.go index 8736874d6..a89ba57b2 100644 --- a/utils/errors.go +++ b/utils/errors.go @@ -33,7 +33,7 @@ var ( ErrorRunningCommand = errors.New("Failed to run the command specified in the template (config.json)") ErrorRunningCommandStream = errors.New("Failed to run the command specified in the template (config.json): %s") ErrorLoadingEnvVars = errors.New("Failed to load the edge applications's environment variables. Verify if the environment variables exist and/or if their values are valid and try again") - ErrorOpeningAzionJsonFile = errors.New("Failed to open the azion.json file. The file doesn't exist, is corrupted, or has an invalid JSON format. Verify if the file format is JSON or fix its content according to the JSON format specification at https://www.json.org/json-en.html") + ErrorOpeningAzionJsonFile = errors.New("Failed to open the azion.json file. The file doesn't exist, is corrupted, or has an invalid JSON format. Verify if you have initialized your project, if the file format is JSON or fix its content according to the JSON format specification at https://www.json.org/json-en.html") ErrorUnmarshalAzionJsonFile = errors.New("Failed to parse the given 'azion.json' file. Verify if the file format is JSON or fix its content according to the JSON format specification at https://www.json.org/json-en.html") ErrorMarshalAzionJsonFile = errors.New("Failed to encode the given 'azion.json' file. Verify if the file format is JSON or fix its content according to the JSON format specification at https://www.json.org/json-en.html") ErrorWritingAzionJsonFile = errors.New("Failed to write in the given 'azion.json' file. Verify if the file is writable and/or you have access to it, if the data format is JSON, or fix the content according to the JSON format specification at https://www.json.org/json-en.html") From ab1d78215992f96ec644c77796850db692102030 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Tue, 5 Sep 2023 18:07:52 -0300 Subject: [PATCH 02/10] chore: if root command is called with -t, help is not called --- pkg/cmd/root/help.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/cmd/root/help.go b/pkg/cmd/root/help.go index 53a318871..dcde9456f 100644 --- a/pkg/cmd/root/help.go +++ b/pkg/cmd/root/help.go @@ -53,6 +53,11 @@ func rootHelpFunc(f *cmdutil.Factory, command *cobra.Command, args []string) { return } + // in case root command is run only with --token flag, we only show the token being saved + if command.Flags().Changed("token") { + return + } + var ( baseCommands []string subcmdCommands []string From b97bf7060b7ad9fcc92196bfd775fdee75a8b36d Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:28:08 -0300 Subject: [PATCH 03/10] feat: azion is an alias for azion init --- pkg/cmd/init/init.go | 47 +++++++++++++------------ pkg/cmd/root/root.go | 82 +++++++++++++++++++++++++++++++------------- 2 files changed, 83 insertions(+), 46 deletions(-) diff --git a/pkg/cmd/init/init.go b/pkg/cmd/init/init.go index 13d1e007e..81973b4bb 100644 --- a/pkg/cmd/init/init.go +++ b/pkg/cmd/init/init.go @@ -11,7 +11,6 @@ import ( "github.com/aziontech/azion-cli/pkg/cmd/deploy" "github.com/aziontech/azion-cli/pkg/cmd/dev" "github.com/aziontech/azion-cli/pkg/cmdutil" - "github.com/aziontech/azion-cli/pkg/contracts" "github.com/aziontech/azion-cli/pkg/iostreams" "github.com/aziontech/azion-cli/pkg/logger" "github.com/aziontech/azion-cli/utils" @@ -90,7 +89,6 @@ func NewInitCmd(f *cmdutil.Factory) *InitCmd { } func NewCobraCmd(init *InitCmd, f *cmdutil.Factory) *cobra.Command { - options := &contracts.AzionApplicationOptions{} info := &InitInfo{} cobraCmd := &cobra.Command{ Use: msg.EdgeApplicationsInitUsage, @@ -108,7 +106,7 @@ func NewCobraCmd(init *InitCmd, f *cmdutil.Factory) *cobra.Command { `), RunE: func(cmd *cobra.Command, args []string) error { info.GlobalFlagAll = f.GlobalFlagAll - return init.run(info, options, cmd) + return init.Run(info) }, } @@ -122,7 +120,7 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { return NewCobraCmd(NewInitCmd(f), f) } -func (cmd *InitCmd) run(info *InitInfo, options *contracts.AzionApplicationOptions, c *cobra.Command) error { +func (cmd *InitCmd) Run(info *InitInfo) error { logger.Debug("Running init command") path, err := cmd.GetWorkDir() @@ -134,17 +132,17 @@ func (cmd *InitCmd) run(info *InitInfo, options *contracts.AzionApplicationOptio switch info.Template { case "simple": - return initSimple(cmd, path, info, c) + return initSimple(cmd, path, info) case "static": - return initStatic(cmd, info, options, c) + return initStatic(cmd, info) } // Checks for global --yes flag and that name flag was not sent - if info.GlobalFlagAll && !c.Flags().Changed("name") { + if info.GlobalFlagAll && info.Name == "" { info.Name = thoth.GenerateName() } else { // if name was not sent we ask for input, otherwise info.Name already has the value - if !c.Flags().Changed("name") { + if info.Name == "" { projName, err := askForInput(msg.InitProjectQuestion, thoth.GenerateName()) if err != nil { return err @@ -154,11 +152,9 @@ func (cmd *InitCmd) run(info *InitInfo, options *contracts.AzionApplicationOptio } } - if !c.Flags().Changed("template") || !c.Flags().Changed("mode") { - err = cmd.selectVulcanTemplates(info) - if err != nil { - return err - } + err = cmd.selectVulcanTemplates(info) + if err != nil { + return err } info.PathWorkingDir = info.PathWorkingDir + "/" + info.Name @@ -172,7 +168,7 @@ func (cmd *InitCmd) run(info *InitInfo, options *contracts.AzionApplicationOptio err = cmd.ChangeDir(info.PathWorkingDir) if err != nil { logger.Debug("Error while changing to new working directory", zap.Error(err)) - return msg.ErrorDeps + return msg.ErrorWorkingDir } shouldDev, err := cmd.ShouldDevDeploy(info, "Do you want to start a local development server?") @@ -180,18 +176,21 @@ func (cmd *InitCmd) run(info *InitInfo, options *contracts.AzionApplicationOptio return err } if shouldDev { - - shouldYarn, err := cmd.ShouldDevDeploy(info, "Do you want to install project dependencies? This may be required to start local development server") + shouldDeps, err := cmd.ShouldDevDeploy(info, "Do you want to install project dependencies? This may be required to start local development server") if err != err { return err } - if shouldYarn { - err = yarnInstall(cmd) + if shouldDeps { + answer, err := getPackageManager() if err != nil { - logger.Debug("Failed to install project dependencies") return err } + err = depsInstall(cmd, answer) + if err != nil { + logger.Debug("Error while installing project dependencies", zap.Error(err)) + return msg.ErrorDeps + } } logger.Debug("Running dev command from init command") @@ -210,13 +209,17 @@ func (cmd *InitCmd) run(info *InitInfo, options *contracts.AzionApplicationOptio return err } if shouldDeploy { - shouldYarn, err := cmd.ShouldDevDeploy(info, "Do you want to install project dependencies? This may be required to deploy your project") + shouldDeps, err := cmd.ShouldDevDeploy(info, "Do you want to install project dependencies? This may be required to deploy your project") if err != err { return err } - if shouldYarn { - err = yarnInstall(cmd) + if shouldDeps { + answer, err := getPackageManager() + if err != nil { + return err + } + err = depsInstall(cmd, answer) if err != nil { logger.Debug("Failed to install project dependencies") return err diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index fe3bed441..3fbdb91e0 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -23,15 +23,32 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" "github.com/spf13/viper" + "go.uber.org/zap" ) +type RootCmd struct { + F *cmdutil.Factory + InitCmd func(f *cmdutil.Factory) *initcmd.InitCmd +} + +func NewRootCmd(f *cmdutil.Factory) *RootCmd { + return &RootCmd{ + F: f, + InitCmd: initcmd.NewInitCmd, + } +} + var ( tokenFlag string configFlag string ) -func NewRootCmd(f *cmdutil.Factory) *cobra.Command { - rootCmd := &cobra.Command{ +func NewCmd(f *cmdutil.Factory) *cobra.Command { + return NewCobraCmd(NewRootCmd(f), f) +} + +func NewCobraCmd(rootCmd *RootCmd, f *cmdutil.Factory) *cobra.Command { + cobraCmd := &cobra.Command{ Use: msg.RootUsage, Long: msg.RootDescription, Short: color.New(color.Bold).Sprint(fmt.Sprintf(msg.RootDescription, version.BinVersion)), @@ -50,46 +67,63 @@ func NewRootCmd(f *cmdutil.Factory) *cobra.Command { Example: heredoc.Doc(` $ azion $ azion -t azionb43a9554776zeg05b11cb1declkbabcc9la + $ azion --debug $ azion -h `), RunE: func(cmd *cobra.Command, args []string) error { - return cmd.Help() + if cmd.Flags().Changed("token") { + return nil + } + return rootCmd.Run() }, SilenceErrors: true, // Silence errors, so the help message won't be shown on flag error SilenceUsage: true, // Silence usage on error } - rootCmd.SetIn(f.IOStreams.In) - rootCmd.SetOut(f.IOStreams.Out) - rootCmd.SetErr(f.IOStreams.Err) + cobraCmd.SetIn(f.IOStreams.In) + cobraCmd.SetOut(f.IOStreams.Out) + cobraCmd.SetErr(f.IOStreams.Err) - rootCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { + cobraCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { rootHelpFunc(f, cmd, args) }) //Global flags - rootCmd.PersistentFlags().StringVarP(&tokenFlag, "token", "t", "", msg.RootTokenFlag) - rootCmd.PersistentFlags().StringVarP(&configFlag, "config", "c", "", msg.RootConfigFlag) - rootCmd.PersistentFlags().BoolVarP(&f.GlobalFlagAll, "yes", "y", false, msg.RootYesFlag) - rootCmd.PersistentFlags().BoolVarP(&f.Debug, "debug", "d", false, msg.RootLogDebug) - rootCmd.PersistentFlags().BoolVarP(&f.Silent, "silent", "s", false, msg.RootLogSilent) - rootCmd.PersistentFlags().StringVarP(&f.LogLevel, "log-level", "l", "info", msg.RootLogDebug) + cobraCmd.PersistentFlags().StringVarP(&tokenFlag, "token", "t", "", msg.RootTokenFlag) + cobraCmd.PersistentFlags().StringVarP(&configFlag, "config", "c", "", msg.RootConfigFlag) + cobraCmd.PersistentFlags().BoolVarP(&f.GlobalFlagAll, "yes", "y", false, msg.RootYesFlag) + cobraCmd.PersistentFlags().BoolVarP(&f.Debug, "debug", "d", false, msg.RootLogDebug) + cobraCmd.PersistentFlags().BoolVarP(&f.Silent, "silent", "s", false, msg.RootLogSilent) + cobraCmd.PersistentFlags().StringVarP(&f.LogLevel, "log-level", "l", "info", msg.RootLogDebug) //other flags - rootCmd.Flags().BoolP("help", "h", false, msg.RootHelpFlag) + cobraCmd.Flags().BoolP("help", "h", false, msg.RootHelpFlag) //set template for -v flag - rootCmd.SetVersionTemplate(color.New(color.Bold).Sprint("Azion CLI " + version.BinVersion + "\n")) // TODO: Change to version.BinVersion once 1.0 is released + cobraCmd.SetVersionTemplate(color.New(color.Bold).Sprint("Azion CLI " + version.BinVersion + "\n")) + + cobraCmd.AddCommand(initcmd.NewCmd(f)) + cobraCmd.AddCommand(deploycmd.NewCmd(f)) + cobraCmd.AddCommand(buildCmd.NewCmd(f)) + cobraCmd.AddCommand(devcmd.NewCmd(f)) + cobraCmd.AddCommand(linkcmd.NewCmd(f)) + cobraCmd.AddCommand(personal_token.NewCmd(f)) + cobraCmd.AddCommand(completion.NewCmd(f)) - rootCmd.AddCommand(initcmd.NewCmd(f)) - rootCmd.AddCommand(deploycmd.NewCmd(f)) - rootCmd.AddCommand(buildCmd.NewCmd(f)) - rootCmd.AddCommand(devcmd.NewCmd(f)) - rootCmd.AddCommand(linkcmd.NewCmd(f)) - rootCmd.AddCommand(personal_token.NewCmd(f)) - rootCmd.AddCommand(completion.NewCmd(f)) + return cobraCmd +} + +func (cmd *RootCmd) Run() error { + logger.Debug("Running root command") + info := &initcmd.InitInfo{} + init := cmd.InitCmd(cmd.F) + err := init.Run(info) + if err != nil { + logger.Debug("Error while running build command called by dev command", zap.Error(err)) + return err + } - return rootCmd + return nil } func Execute() { @@ -112,7 +146,7 @@ func Execute() { Config: viper.GetViper(), } - cmd := NewRootCmd(factory) + cmd := NewCmd(factory) cobra.CheckErr(cmd.Execute()) } From aeaf2a4430bd8b2608e70afc6eba91d412f13985 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:32:01 -0300 Subject: [PATCH 04/10] chore: improve error and debug messages --- messages/init/errors.go | 1 + messages/init/messages.go | 5 +++-- messages/link/errors.go | 1 + messages/link/messages.go | 2 +- utils/errors.go | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/messages/init/errors.go b/messages/init/errors.go index 7f592af16..a4f19e010 100644 --- a/messages/init/errors.go +++ b/messages/init/errors.go @@ -21,4 +21,5 @@ var ( ErrorFailedCreatingWorkerDirectory = errors.New("Failed to create the worker directory. The worker's parent directory is read-only and/or isn't accessible. Change the permissions of the parent directory to read and write and/or give access to it") ErrorFailedCreatingAzionDirectory = errors.New("Failed to create the azion directory. The public's parent directory is read-only and/or isn't accessible. Change the permissions of the parent directory to read and write and/or give access to it") ErrorDeps = errors.New("Failed to install project dependencies") + ErrorWorkingDir = errors.New("Failed to change current working directory") ) diff --git a/messages/init/messages.go b/messages/init/messages.go index 6c7864168..3cd00abe9 100644 --- a/messages/init/messages.go +++ b/messages/init/messages.go @@ -3,7 +3,7 @@ package init var ( //init cmd - EdgeApplicationsInitUsage = `init [flags]` + EdgeApplicationsInitUsage = `init [flags]` EdgeApplicationsInitShortDescription = "Initializes an Edge Application" EdgeApplicationsInitLongDescription = "Defines primary parameters based on a given name and application preset to start an Edge Application on the Azion’s platform" EdgeApplicationsInitRunningCmd = "Running init step command:\n\n" @@ -14,7 +14,8 @@ var ( EdgeApplicationsInitFlagNo = "Answers all yes/no interactions automatically with no" WebAppInitContentOverridden = "This project was already configured. Do you want to override the previous configuration? (default: no) " WebAppInitCmdSuccess = "Template successfully fetched and configured\n\n" - InitGettingTemplates = "Getting modes available" + InitGettingTemplates = "Getting modes available\n" + InitGettingVulcan = "Getting templates available\n" InitProjectQuestion = "(Hit enter to accept the suggested name in parenthesis) Your project's name: " EdgeApplicationsInitFlagHelp = "Displays more information about the init command" EdgeApplicationsInitSuccessful = "Your project %s was initialized successfully\n" diff --git a/messages/link/errors.go b/messages/link/errors.go index c23fd8251..88fdff9a5 100644 --- a/messages/link/errors.go +++ b/messages/link/errors.go @@ -20,4 +20,5 @@ var ( ErrorFailedCreatingWorkerDirectory = errors.New("Failed to create the worker directory. The worker's parent directory is read-only and/or isn't accessible. Change the permissions of the parent directory to read and write and/or give access to it") ErrorFailedCreatingAzionDirectory = errors.New("Failed to create the azion directory. The public's parent directory is read-only and/or isn't accessible. Change the permissions of the parent directory to read and write and/or give access to it") ErrReadEnvFile = errors.New("Failed to read the webdev.env file. Verify if the file is corrupted or changed or run the 'azioncli edge_applications publish' command again") + ErrorDeps = errors.New("Failed to install project dependencies") ) diff --git a/messages/link/messages.go b/messages/link/messages.go index 2cc015770..30d164696 100644 --- a/messages/link/messages.go +++ b/messages/link/messages.go @@ -11,7 +11,7 @@ var ( EdgeApplicationsLinkFlagTemplate = "The Edge Application's preset" EdgeApplicationsLinkFlagMode = "The Edge Application's mode" WebAppLinkCmdSuccess = "Template successfully fetched and configured\n\n" - LinkGettingTemplates = "Getting templates available" + LinkGettingTemplates = "Getting templates available\n" LinkProjectQuestion = "(Hit enter to accept the suggested name in parenthesis) Your project's name: " EdgeApplicationsLinkFlagHelp = "Displays more information about the link command" EdgeApplicationsLinkSuccessful = "Your project %s was linked successfully\n" diff --git a/utils/errors.go b/utils/errors.go index a89ba57b2..14b83593f 100644 --- a/utils/errors.go +++ b/utils/errors.go @@ -14,7 +14,7 @@ var ( ErrorParsingModel = errors.New("Failed in parsing the model") ErrorExecTemplate = errors.New("Failed to apply template to given data and store result in buffer") ErrorInvalidVariablesFileFormat = errors.New("The format of the variables in the file is invalid. You must provide a file with valid variable formats. Use the flags -h or --help with a command or subcommand to display more information") - ErrorInternalServerError = errors.New("The server could not process the request because an internal and unexpected problem occurred. Wait a few seconds and try again. Contact Azion’s support for more information") + ErrorInternalServerError = errors.New("The server could not process the request because an internal and unexpected problem occurred. Wait a few seconds and try again. For more information run the command again using the '--debug' flag. If the problem persists, contact Azion’s support") ErrorUpdateNoFlagsSent = errors.New("The subcommand update needs at least one flag with a valid value. Run the command `azioncli update --help` to display more information and try again") ErrorUnmarshalReader = errors.New("Failed to decode the given 'azion.json' file. Verify if the file format is JSON or fix its content according to the JSON format specification at https://www.json.org/json-en.html") ErrorFormatOut = errors.New("The server failed formatting data for display. Repeat the HTTP request and check the HTTP response's format") From 8e00d6aa86d00f474c0187634f8c1d0ad5c0f6a7 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:33:00 -0300 Subject: [PATCH 05/10] chore: remove worker id from function call --- pkg/api/storage/storage.go | 2 +- pkg/cmd/deploy/upload.go | 2 +- pkg/cmd/deploy/worker.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/api/storage/storage.go b/pkg/api/storage/storage.go index 1db154d92..2cdb158af 100644 --- a/pkg/api/storage/storage.go +++ b/pkg/api/storage/storage.go @@ -35,7 +35,7 @@ func (c *Client) Upload(ctx context.Context, fileOps *contracts.FileOps) error { req := c.apiClient.DefaultApi.StorageVersionIdPost(ctx, fileOps.VersionID).XAzionStaticPath(fileOps.Path).Body(fileOps.FileContent).ContentType(fileOps.MimeType) _, httpResp, err := req.Execute() if err != nil { - logger.Debug("Error while uploading file to storage api", zap.Error(err)) + logger.Debug("Error while uploading file <"+fileOps.Path+"> to storage api", zap.Error(err)) return utils.ErrorPerStatusCode(httpResp, err) } return nil diff --git a/pkg/cmd/deploy/upload.go b/pkg/cmd/deploy/upload.go index af6423961..53f9473b9 100644 --- a/pkg/cmd/deploy/upload.go +++ b/pkg/cmd/deploy/upload.go @@ -43,7 +43,7 @@ func (cmd *DeployCmd) uploadFiles(f *cmdutil.Factory, pathStatic string, version // Create worker goroutines for i := 1; i <= noOfWorkers; i++ { - go worker(i, jobs, results, ¤tFile, clientUpload) + go worker(jobs, results, ¤tFile, clientUpload) } bar := progressbar.NewOptions( diff --git a/pkg/cmd/deploy/worker.go b/pkg/cmd/deploy/worker.go index 99c81139b..17a18d630 100644 --- a/pkg/cmd/deploy/worker.go +++ b/pkg/cmd/deploy/worker.go @@ -11,7 +11,7 @@ import ( ) // worker reads the range of jobs and uploads the file, if there is an error during upload, we returning it through the results channel -func worker(wID int, jobs <-chan contracts.FileOps, results chan<- error, currentFile *int64, clientUpload *storage.Client) { +func worker(jobs <-chan contracts.FileOps, results chan<- error, currentFile *int64, clientUpload *storage.Client) { for job := range jobs { if err := clientUpload.Upload(context.Background(), &job); err != nil { From 44febdf8a0b6d74fa6b914986fff40a6b06ccda1 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:33:55 -0300 Subject: [PATCH 06/10] refactor: remove unnecessary code --- pkg/cmd/init/simple.go | 3 +-- pkg/cmd/init/static.go | 6 ++---- pkg/cmd/link/simple.go | 3 +-- pkg/cmd/link/static.go | 5 ++--- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/pkg/cmd/init/simple.go b/pkg/cmd/init/simple.go index 2aaca0dd1..9a84747b8 100644 --- a/pkg/cmd/init/simple.go +++ b/pkg/cmd/init/simple.go @@ -9,11 +9,10 @@ import ( "github.com/aziontech/azion-cli/pkg/contracts" "github.com/aziontech/azion-cli/pkg/logger" "github.com/aziontech/azion-cli/utils" - "github.com/spf13/cobra" "go.uber.org/zap" ) -func initSimple(cmd *InitCmd, path string, info *InitInfo, c *cobra.Command) error { +func initSimple(cmd *InitCmd, path string, info *InitInfo) error { var err error var shouldFetchTemplates bool options := &contracts.AzionApplicationSimple{} diff --git a/pkg/cmd/init/static.go b/pkg/cmd/init/static.go index da1176093..31958173e 100644 --- a/pkg/cmd/init/static.go +++ b/pkg/cmd/init/static.go @@ -4,13 +4,11 @@ import ( "fmt" msg "github.com/aziontech/azion-cli/messages/init" - "github.com/aziontech/azion-cli/pkg/contracts" "github.com/aziontech/azion-cli/pkg/logger" thoth "github.com/aziontech/go-thoth" - "github.com/spf13/cobra" ) -func initStatic(cmd *InitCmd, info *InitInfo, options *contracts.AzionApplicationOptions, c *cobra.Command) error { +func initStatic(cmd *InitCmd, info *InitInfo) error { shouldFetchTemplates, err := shouldFetch(cmd, info) if err != nil { return err @@ -20,7 +18,7 @@ func initStatic(cmd *InitCmd, info *InitInfo, options *contracts.AzionApplicatio if info.GlobalFlagAll { info.Name = thoth.GenerateName() } else { - if !c.Flags().Changed("name") { + if info.Name == "" { projName, err := askForInput(msg.InitProjectQuestion, thoth.GenerateName()) if err != nil { return err diff --git a/pkg/cmd/link/simple.go b/pkg/cmd/link/simple.go index 17c699485..d11f13374 100644 --- a/pkg/cmd/link/simple.go +++ b/pkg/cmd/link/simple.go @@ -9,11 +9,10 @@ import ( "github.com/aziontech/azion-cli/pkg/contracts" "github.com/aziontech/azion-cli/pkg/logger" "github.com/aziontech/azion-cli/utils" - "github.com/spf13/cobra" "go.uber.org/zap" ) -func initSimple(cmd *LinkCmd, path string, info *LinkInfo, c *cobra.Command) error { +func initSimple(cmd *LinkCmd, path string, info *LinkInfo) error { var err error var shouldFetchTemplates bool options := &contracts.AzionApplicationSimple{} diff --git a/pkg/cmd/link/static.go b/pkg/cmd/link/static.go index 5397978c5..c25495bf4 100644 --- a/pkg/cmd/link/static.go +++ b/pkg/cmd/link/static.go @@ -7,10 +7,9 @@ import ( "github.com/aziontech/azion-cli/pkg/contracts" "github.com/aziontech/azion-cli/pkg/logger" thoth "github.com/aziontech/go-thoth" - "github.com/spf13/cobra" ) -func initStatic(cmd *LinkCmd, info *LinkInfo, options *contracts.AzionApplicationOptions, c *cobra.Command) error { +func initStatic(cmd *LinkCmd, info *LinkInfo, options *contracts.AzionApplicationOptions) error { shouldFetchTemplates, err := shouldFetch(cmd, info) if err != nil { return err @@ -20,7 +19,7 @@ func initStatic(cmd *LinkCmd, info *LinkInfo, options *contracts.AzionApplicatio if info.GlobalFlagAll { info.Name = thoth.GenerateName() } else { - if !c.Flags().Changed("name") { + if info.Name == "" { projName, err := askForInput(msg.LinkProjectQuestion, thoth.GenerateName()) if err != nil { return err From dc255205c3629dba02ebc2e68f53737e8aaa27c1 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:35:12 -0300 Subject: [PATCH 07/10] refactor: restructure commands checking var values instead of flags --- cmd/gen_docs/main.go | 2 +- pkg/cmd/init/utils.go | 70 +++++++++++++++++++++++++++---------------- pkg/cmd/link/link.go | 33 ++++++++++++-------- pkg/cmd/link/utils.go | 21 ++++++++++--- 4 files changed, 82 insertions(+), 44 deletions(-) diff --git a/cmd/gen_docs/main.go b/cmd/gen_docs/main.go index 01b485c7c..81388a248 100644 --- a/cmd/gen_docs/main.go +++ b/cmd/gen_docs/main.go @@ -41,7 +41,7 @@ func run(args []string) error { return fmt.Errorf("error: --doc-path not set") } - rootCmd := cmd.NewRootCmd(&cmdutil.Factory{ + rootCmd := cmd.NewCmd(&cmdutil.Factory{ IOStreams: iostreams.System(), }) rootCmd.InitDefaultHelpCmd() diff --git a/pkg/cmd/init/utils.go b/pkg/cmd/init/utils.go index f68dae1cd..632d5f3af 100644 --- a/pkg/cmd/init/utils.go +++ b/pkg/cmd/init/utils.go @@ -1,6 +1,7 @@ package init import ( + "fmt" "strings" "github.com/AlecAivazis/survey/v2" @@ -68,47 +69,50 @@ func askForInput(msg string, defaultIn string) (string, error) { } func (cmd *InitCmd) selectVulcanTemplates(info *InitInfo) error { - logger.FInfo(cmd.Io.Out, msg.InitGettingTemplates) + logger.FInfo(cmd.Io.Out, msg.InitGettingVulcan) err := cmd.CommandRunInteractive(cmd.F, "npx --yes edge-functions@1.5.0 init --name "+info.Name) if err != nil { return err } - output, _, err := cmd.CommandRunner("npx --yes edge-functions@1.5.0 presets ls", []string{"CLEAN_OUTPUT_MODE=true"}) - if err != nil { - return err - } + if info.Template == "" || info.Mode == "" { + output, _, err := cmd.CommandRunner("npx --yes edge-functions@1.5.0 presets ls", []string{"CLEAN_OUTPUT_MODE=true"}) + if err != nil { + return err + } - newLineSplit := strings.Split(output, "\n") - newLineSplit[len(newLineSplit)-1] = "static (azion)" + newLineSplit := strings.Split(output, "\n") + newLineSplit[len(newLineSplit)-1] = "static (azion)" - answer := "" - template := "" - mode := "" - prompt := &survey.Select{ - Message: "Choose a mode:", - Options: newLineSplit, - } - err = survey.AskOne(prompt, &answer) - if err != nil { - return err - } + answer := "" + template := "" + mode := "" + prompt := &survey.Select{ + Message: "Choose a mode:", + Options: newLineSplit, + } + err = survey.AskOne(prompt, &answer) + if err != nil { + return err + } - modeSplit := strings.Split(answer, " ") - template = modeSplit[0] - mode = strings.Replace(strings.Replace(modeSplit[1], "(", "", -1), ")", "", -1) + modeSplit := strings.Split(answer, " ") + template = modeSplit[0] + mode = strings.Replace(strings.Replace(modeSplit[1], "(", "", -1), ")", "", -1) - info.Template = template - info.Mode = mode + info.Template = template + info.Mode = mode + + } return nil } -func yarnInstall(cmd *InitCmd) error { +func depsInstall(cmd *InitCmd, packageManager string) error { logger.FInfo(cmd.Io.Out, msg.InitInstallDeps) - - err := cmd.CommandRunInteractive(cmd.F, "yarn install") + command := fmt.Sprintf("%s install", packageManager) + err := cmd.CommandRunInteractive(cmd.F, command) if err != nil { logger.Debug("Error while running command with simultaneous output", zap.Error(err)) return msg.ErrorDeps @@ -116,3 +120,17 @@ func yarnInstall(cmd *InitCmd) error { return nil } + +func getPackageManager() (string, error) { + opts := []string{"npm", "yarn"} + answer := "" + prompt := &survey.Select{ + Message: "Choose a package manager:", + Options: opts, + } + err := survey.AskOne(prompt, &answer) + if err != nil { + return "", err + } + return answer, nil +} diff --git a/pkg/cmd/link/link.go b/pkg/cmd/link/link.go index b01199e4b..52c8b52ea 100644 --- a/pkg/cmd/link/link.go +++ b/pkg/cmd/link/link.go @@ -105,7 +105,7 @@ func NewCobraCmd(link *LinkCmd, f *cmdutil.Factory) *cobra.Command { `), RunE: func(cmd *cobra.Command, args []string) error { info.GlobalFlagAll = f.GlobalFlagAll - return link.run(info, options, cmd) + return link.run(info, options) }, } @@ -121,8 +121,8 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { return NewCobraCmd(NewLinkCmd(f), f) } -func (cmd *LinkCmd) run(info *LinkInfo, options *contracts.AzionApplicationOptions, c *cobra.Command) error { - logger.Debug("Running link subcommand from edge_applications command tree") +func (cmd *LinkCmd) run(info *LinkInfo, options *contracts.AzionApplicationOptions) error { + logger.Debug("Running link command") path, err := cmd.GetWorkDir() if err != nil { @@ -141,9 +141,9 @@ func (cmd *LinkCmd) run(info *LinkInfo, options *contracts.AzionApplicationOptio switch info.Preset { case "simple": - return initSimple(cmd, path, info, c) + return initSimple(cmd, path, info) case "static": - return initStatic(cmd, info, options, c) + return initStatic(cmd, info, options) } shouldFetchTemplates, err := shouldFetch(cmd, info) @@ -153,21 +153,20 @@ func (cmd *LinkCmd) run(info *LinkInfo, options *contracts.AzionApplicationOptio if shouldFetchTemplates { // Checks for global --yes flag and that name flag was not sent - if info.GlobalFlagAll && !c.Flags().Changed("name") { + if (info.GlobalFlagAll || info.Auto) && info.Name == "" { info.Name = thoth.GenerateName() } else { // if name was not sent we ask for input, otherwise info.Name already has the value - if !c.Flags().Changed("name") { + if info.Name == "" { projName, err := askForInput(msg.LinkProjectQuestion, thoth.GenerateName()) if err != nil { return err } - info.Name = projName } } - if !c.Flags().Changed("preset") || !c.Flags().Changed("mode") { + if info.Preset == "" || info.Mode == "" { err = cmd.selectVulcanMode(info) if err != nil { return err @@ -192,11 +191,15 @@ func (cmd *LinkCmd) run(info *LinkInfo, options *contracts.AzionApplicationOptio } if shouldDeps { - err = yarnInstall(cmd) + answer, err := getPackageManager() if err != nil { - logger.Debug("Failed to install project dependencies") return err } + err = depsInstall(cmd, answer) + if err != nil { + logger.Debug("Error while installing project dependencies", zap.Error(err)) + return msg.ErrorDeps + } } logger.Debug("Running dev command from link command") @@ -221,11 +224,15 @@ func (cmd *LinkCmd) run(info *LinkInfo, options *contracts.AzionApplicationOptio } if shouldYarn { - err = yarnInstall(cmd) + answer, err := getPackageManager() if err != nil { - logger.Debug("Failed to install project dependencies") return err } + err = depsInstall(cmd, answer) + if err != nil { + logger.Debug("Error while installing project dependencies", zap.Error(err)) + return msg.ErrorDeps + } } logger.Debug("Running deploy command from link command") diff --git a/pkg/cmd/link/utils.go b/pkg/cmd/link/utils.go index 882d8fde4..58d5131cc 100644 --- a/pkg/cmd/link/utils.go +++ b/pkg/cmd/link/utils.go @@ -119,11 +119,10 @@ func (cmd *LinkCmd) selectVulcanMode(info *LinkInfo) error { return nil } -func yarnInstall(cmd *LinkCmd) error { - +func depsInstall(cmd *LinkCmd, packageManager string) error { logger.FInfo(cmd.Io.Out, msg.InitInstallDeps) - - err := cmd.CommandRunInteractive(cmd.F, "yarn install") + command := fmt.Sprintf("%s install", packageManager) + err := cmd.CommandRunInteractive(cmd.F, command) if err != nil { logger.Debug("Error while running command with simultaneous output", zap.Error(err)) return msg.ErrorDeps @@ -131,3 +130,17 @@ func yarnInstall(cmd *LinkCmd) error { return nil } + +func getPackageManager() (string, error) { + opts := []string{"npm", "yarn"} + answer := "" + prompt := &survey.Select{ + Message: "Choose a package manager:", + Options: opts, + } + err := survey.AskOne(prompt, &answer) + if err != nil { + return "", err + } + return answer, nil +} From 838ef7b72ccf354759a149d3c38d368b36d7f5e8 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:44:43 -0300 Subject: [PATCH 08/10] refactor: fix debug message in root command --- pkg/cmd/root/root.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index 3fbdb91e0..44d7a1a5d 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -119,7 +119,7 @@ func (cmd *RootCmd) Run() error { init := cmd.InitCmd(cmd.F) err := init.Run(info) if err != nil { - logger.Debug("Error while running build command called by dev command", zap.Error(err)) + logger.Debug("Error while running init command called by root command", zap.Error(err)) return err } From 0238d64372cb76a76becff0b8ea5e2432318e7f1 Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Wed, 6 Sep 2023 14:53:28 -0300 Subject: [PATCH 09/10] refactor: make GetPackageManager function global --- pkg/cmd/init/init.go | 4 ++-- pkg/cmd/init/utils.go | 14 -------------- pkg/cmd/link/link.go | 4 ++-- pkg/cmd/link/utils.go | 14 -------------- utils/helpers.go | 15 +++++++++++++++ 5 files changed, 19 insertions(+), 32 deletions(-) diff --git a/pkg/cmd/init/init.go b/pkg/cmd/init/init.go index 81973b4bb..fcc96c043 100644 --- a/pkg/cmd/init/init.go +++ b/pkg/cmd/init/init.go @@ -182,7 +182,7 @@ func (cmd *InitCmd) Run(info *InitInfo) error { } if shouldDeps { - answer, err := getPackageManager() + answer, err := utils.GetPackageManager() if err != nil { return err } @@ -215,7 +215,7 @@ func (cmd *InitCmd) Run(info *InitInfo) error { } if shouldDeps { - answer, err := getPackageManager() + answer, err := utils.GetPackageManager() if err != nil { return err } diff --git a/pkg/cmd/init/utils.go b/pkg/cmd/init/utils.go index 632d5f3af..5ac8bbd24 100644 --- a/pkg/cmd/init/utils.go +++ b/pkg/cmd/init/utils.go @@ -120,17 +120,3 @@ func depsInstall(cmd *InitCmd, packageManager string) error { return nil } - -func getPackageManager() (string, error) { - opts := []string{"npm", "yarn"} - answer := "" - prompt := &survey.Select{ - Message: "Choose a package manager:", - Options: opts, - } - err := survey.AskOne(prompt, &answer) - if err != nil { - return "", err - } - return answer, nil -} diff --git a/pkg/cmd/link/link.go b/pkg/cmd/link/link.go index 52c8b52ea..a44665f4e 100644 --- a/pkg/cmd/link/link.go +++ b/pkg/cmd/link/link.go @@ -191,7 +191,7 @@ func (cmd *LinkCmd) run(info *LinkInfo, options *contracts.AzionApplicationOptio } if shouldDeps { - answer, err := getPackageManager() + answer, err := utils.GetPackageManager() if err != nil { return err } @@ -224,7 +224,7 @@ func (cmd *LinkCmd) run(info *LinkInfo, options *contracts.AzionApplicationOptio } if shouldYarn { - answer, err := getPackageManager() + answer, err := utils.GetPackageManager() if err != nil { return err } diff --git a/pkg/cmd/link/utils.go b/pkg/cmd/link/utils.go index 58d5131cc..460bc3c71 100644 --- a/pkg/cmd/link/utils.go +++ b/pkg/cmd/link/utils.go @@ -130,17 +130,3 @@ func depsInstall(cmd *LinkCmd, packageManager string) error { return nil } - -func getPackageManager() (string, error) { - opts := []string{"npm", "yarn"} - answer := "" - prompt := &survey.Select{ - Message: "Choose a package manager:", - Options: opts, - } - err := survey.AskOne(prompt, &answer) - if err != nil { - return "", err - } - return answer, nil -} diff --git a/utils/helpers.go b/utils/helpers.go index f171f487c..1275e5ff9 100644 --- a/utils/helpers.go +++ b/utils/helpers.go @@ -12,6 +12,7 @@ import ( "strings" "time" + "github.com/AlecAivazis/survey/v2" msg "github.com/aziontech/azion-cli/messages/edge_applications" "github.com/aziontech/azion-cli/pkg/cmdutil" "github.com/aziontech/azion-cli/pkg/contracts" @@ -363,3 +364,17 @@ func TruncateString(str string) string { func IsEmpty(str string) bool { return len(str) < 1 } + +func GetPackageManager() (string, error) { + opts := []string{"npm", "yarn"} + answer := "" + prompt := &survey.Select{ + Message: "Choose a package manager:", + Options: opts, + } + err := survey.AskOne(prompt, &answer) + if err != nil { + return "", err + } + return answer, nil +} From 81e42ec4581a404ce65b1931b2cb26bacb2a237c Mon Sep 17 00:00:00 2001 From: PatrickMenoti <82882574+PatrickMenoti@users.noreply.github.com> Date: Wed, 6 Sep 2023 15:10:03 -0300 Subject: [PATCH 10/10] chore: update error message when build command fails --- messages/build/errors.go | 2 +- pkg/cmd/deploy/deploy_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/messages/build/errors.go b/messages/build/errors.go index 209a2b234..6643820d8 100644 --- a/messages/build/errors.go +++ b/messages/build/errors.go @@ -3,7 +3,7 @@ package build import "errors" var ( - ErrorBuilding = errors.New("Failed to build your project. Make sure you have initialized your project by running the init or link commands. For more information run 'azion build --debug' or contact Azion's support") + ErrorBuilding = errors.New("Failed to build your resource. Azion configuration not found. Make sure you are in the root directory of your local repository and have already initialized or linked your resource with the commands 'azion init' or 'azion link'") ErrorVulcanExecute = errors.New("Error executing Vulcan: %s") EdgeApplicationsOutputErr = errors.New("This output-ctrl option is not available. Read the readme files found in the repository https://github.com/aziontech/azioncli-template and try again") ErrFailedToRunBuildCommand = errors.New("Failed to run the build command. Verify if the command is correct and check the output above for more details. Run the 'azion build' command again or contact Azion's support") diff --git a/pkg/cmd/deploy/deploy_test.go b/pkg/cmd/deploy/deploy_test.go index b8e53a2f8..4c56e0236 100644 --- a/pkg/cmd/deploy/deploy_test.go +++ b/pkg/cmd/deploy/deploy_test.go @@ -58,7 +58,7 @@ func TestDeployCmd(t *testing.T) { err := cmd.Execute() - require.EqualError(t, err, "Failed to build your project. Make sure you have initialized your project by running the init or link commands. For more information run 'azion build --debug' or contact Azion's support") + require.EqualError(t, err, "Failed to build your resource. Azion configuration not found. Make sure you are in the root directory of your local repository and have already initialized or linked your resource with the commands 'azion init' or 'azion link'") }) t.Run("failed to create application", func(t *testing.T) {