chore(commands): tidy error paths and drop v1-comparability code

Fix "contaiers" typo (list, rm), route the upgrade error through the
printer, and simplify joinHooks now that tests/compare.sh is gone.

Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
This commit is contained in:
Luca Di Maio
2026-06-25 13:39:47 +02:00
committed by Alessio Biancalana
parent b31ea49e91
commit c71075124b
4 changed files with 14 additions and 17 deletions
+11 -13
View File
@@ -215,24 +215,22 @@ func (ac *AssembleCommand) createItem(ctx context.Context, item manifest.Item, d
}
func (ac *AssembleCommand) joinHooks(hooks []string) string {
sb := strings.Builder{}
// A hook that already ends in its own terminator (`;` or `&&`) keeps
// it; otherwise insert ` && ` so consecutive hooks don't run together.
selfTerminated := regexp.MustCompile(`(;|&&)[[:space:]]?$`)
sb := strings.Builder{}
for i, hook := range hooks {
sb.WriteString(hook)
if i < len(hooks)-1 {
semicolonRegex := regexp.MustCompile(`;[[:space:]]{0,1}$`)
andAndRegex := regexp.MustCompile(`&&[[:space:]]{0,1}$`)
separator := " " // two spaces just because v1 does that, so it's comparable in regression tests
if !semicolonRegex.MatchString(hook) && !andAndRegex.MatchString(hook) {
separator = " && "
}
sb.WriteString(separator)
if i == len(hooks)-1 {
continue
}
if selfTerminated.MatchString(hook) {
sb.WriteString(" ")
} else {
sb.WriteString(" && ")
}
}
return sb.String()
}
+1 -1
View File
@@ -29,7 +29,7 @@ func NewListCommand(cfg *config.Values, cm containermanager.ContainerManager) *L
func (c *ListCommand) Execute(ctx context.Context) (*ListResult, error) {
containers, err := c.containerManager.ListContainers(ctx)
if err != nil {
return nil, fmt.Errorf("failed while listing contaiers: %w", err)
return nil, fmt.Errorf("failed while listing containers: %w", err)
}
var distroboxes []containermanager.Container
+1 -1
View File
@@ -66,7 +66,7 @@ func (c *RmCommand) Execute(ctx context.Context, options RmOptions) (*RmResult,
listResult, err := c.listCmd.Execute(ctx)
if err != nil {
return nil, fmt.Errorf("failed while listing contaiers: %w", err)
return nil, fmt.Errorf("failed while listing containers: %w", err)
}
distroboxesToRemove := getContainersToRemove(listResult.Containers, options.ContainerNames, options.All)
+1 -2
View File
@@ -85,8 +85,7 @@ func (c *UpgradeCommand) Execute(ctx context.Context, opts *UpgradeOptions) erro
// Per-container banner, matching the shell (distrobox-upgrade:267).
c.printer.Println("Upgrading %s...", name)
if err := c.upgradeContainer(ctx, name); err != nil {
//nolint:forbidigo // FIXME: waiting for the logger implementation
fmt.Printf("error upgrading %s: %s\n", name, err)
c.printer.PrintErrorln("error upgrading %s: %s", name, err)
lastErr = err