Skip to content

Commit

Permalink
fix:[#411] stacks update asks for new list of pkgs
Browse files Browse the repository at this point in the history
- stacks update asks if pkgs need to be updated
- takes a space-separated list of packages to replace
  • Loading branch information
jardon committed Oct 17, 2024
1 parent c5caf50 commit fba8730
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
33 changes: 14 additions & 19 deletions cmd/stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ func updateStack(cmd *cobra.Command, args []string) error {
packages, _ := cmd.Flags().GetString("packages")
pkgManager, _ := cmd.Flags().GetString("pkg-manager")

cmdr.Error.Printfln("packages: %s", packages)
if name == "" {
if len(args) != 1 || args[0] == "" {
cmdr.Error.Println(apx.Trans("stacks.update.error.noName"))
Expand Down Expand Up @@ -445,35 +444,31 @@ func updateStack(cmd *cobra.Command, args []string) error {
return nil
}

packagesArray := strings.Fields(packages)
cmdr.Error.Printfln("packagearray: %s", packagesArray)
if len(packages) == 0 && !noPrompt {
if len(stack.Packages) == 0 {
cmdr.Info.Println(apx.Trans("stacks.update.info.noPackages") + "[y/N]")

if len(packages) > 0 {
stack.Packages = strings.Fields(packages)
} else if !noPrompt {
if len(stack.Packages) > 0 {
cmdr.Info.Println(apx.Trans("stacks.update.info.confirmPackages") + "[y/N]" + "\n\t -", strings.Join(stack.Packages, "\n\t - "))
} else {
cmdr.Info.Println(apx.Trans("stacks.update.info.confirmPackages") + "\n\t -", strings.Join(stack.Packages, "\n\t - "))
cmdr.Info.Println(apx.Trans("stacks.update.info.noPackages") + "[y/N]")
}

reader := bufio.NewReader(os.Stdin)
answer, _ := reader.ReadString('\n')
answer = strings.TrimSpace(answer)

packagesArray := []string{}

if answer == "y" || answer == "Y" {
if len(stack.Packages) > 0 {
packagesArray = stack.Packages
} else {
cmdr.Info.Println(apx.Trans("stacks.update.info.askPackages"))
packagesInput, _ := reader.ReadString('\n')
packagesInput = strings.TrimSpace(packagesInput)
packagesArray = strings.Fields(packagesInput)
}
} else {
packagesArray = []string{}
cmdr.Info.Println(apx.Trans("stacks.update.info.askPackages"))
packagesInput, _ := reader.ReadString('\n')
packagesInput = strings.TrimSpace(packagesInput)
packagesArray = strings.Fields(packagesInput)
stack.Packages = packagesArray
}
}

stack.Base = base
stack.Packages = packagesArray
stack.PkgManager = pkgManager

err := stack.Save()
Expand Down
4 changes: 2 additions & 2 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ stacks:
info:
askBase: "Type a new base or confirm the current one (%s):"
askPkgManager: "Choose a new package manager or confirm the current one (%s):"
confirmPackages: "Do you want to confirm the current packages list?"
confirmPackages: "Do you want to update the list of packages?"
noPackages: "You have not provided any packages to install in the stack. Do you
want to add some now?"
askPackages: "Type the packages you want to install in the stack, separated
by a space, or confirm the current ones (%s):"
by a space:"
success: "Updated stack '%s'."
options:
noPrompt:
Expand Down

0 comments on commit fba8730

Please sign in to comment.