From fba8730dc8c4d907d1956383282dacfe7882b48a Mon Sep 17 00:00:00 2001 From: Jarred Wilson Date: Wed, 16 Oct 2024 18:15:08 +0000 Subject: [PATCH] fix:[#411] stacks update asks for new list of pkgs - stacks update asks if pkgs need to be updated - takes a space-separated list of packages to replace --- cmd/stacks.go | 33 ++++++++++++++------------------- locales/en.yml | 4 ++-- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/cmd/stacks.go b/cmd/stacks.go index 8f22519e..39acd7bf 100644 --- a/cmd/stacks.go +++ b/cmd/stacks.go @@ -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")) @@ -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() diff --git a/locales/en.yml b/locales/en.yml index 395a9ffd..15b4f100 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -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: