Skip to content

Commit

Permalink
refactor: make GetPackageManager function global
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickMenoti committed Sep 6, 2023
1 parent 838ef7b commit 0238d64
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 32 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 0 additions & 14 deletions pkg/cmd/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions pkg/cmd/link/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 0 additions & 14 deletions pkg/cmd/link/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 15 additions & 0 deletions utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 0238d64

Please sign in to comment.