chore: add filter to ListMachines

This commit is contained in:
Pavel Sviderski
2025-04-11 21:26:40 +10:00
parent 2f5a2c6344
commit 87331a9265
19 changed files with 129 additions and 76 deletions
+1 -1
View File
@@ -163,7 +163,7 @@ func waitClusterInitialised(ctx context.Context, client *client.Client) error {
), ctx)
check := func() error {
_, err := client.ListMachines(ctx)
_, err := client.ListMachines(ctx, nil)
if err == nil {
return nil
}
+1 -1
View File
@@ -38,7 +38,7 @@ func list(ctx context.Context, uncli *cli.CLI, clusterName string) error {
}
defer client.Close()
machines, err := client.ListMachines(ctx)
machines, err := client.ListMachines(ctx, nil)
if err != nil {
return fmt.Errorf("list machines: %w", err)
}
+1 -1
View File
@@ -50,7 +50,7 @@ func inspect(ctx context.Context, uncli *cli.CLI, opts inspectOptions) error {
return fmt.Errorf("inspect service: %w", err)
}
machines, err := client.ListMachines(ctx)
machines, err := client.ListMachines(ctx, nil)
if err != nil {
return fmt.Errorf("list machines: %w", err)
}
+1 -3
View File
@@ -3,9 +3,7 @@ package service
import (
"context"
"fmt"
"os"
"github.com/docker/cli/cli/streams"
"github.com/docker/compose/v2/pkg/progress"
"github.com/psviderski/uncloud/internal/cli"
"github.com/spf13/cobra"
@@ -49,7 +47,7 @@ func rm(ctx context.Context, uncli *cli.CLI, opts rmOptions) error {
return fmt.Errorf("remove service '%s': %w", s, err)
}
return nil
}, streams.NewOut(os.Stdout), "Removing service "+s)
}, uncli.ProgressOut(), "Removing service "+s)
}
return nil
+1 -1
View File
@@ -85,7 +85,7 @@ func create(ctx context.Context, uncli *cli.CLI, name string, opts createOptions
// List machines and filter by the specified machine name or ID.
// If no machine is specified, prompt the user to select one.
machines, err := client.ListMachines(ctx)
machines, err := client.ListMachines(ctx, nil)
if err != nil {
return fmt.Errorf("list machines: %w", err)
}
+1 -10
View File
@@ -54,16 +54,7 @@ func list(ctx context.Context, uncli *cli.CLI, opts listOptions) error {
// Apply machine filter if specified.
var filter *api.VolumeFilter
if len(opts.machines) > 0 {
// Expand comma-separated machine names.
var machines []string
for _, m := range opts.machines {
for _, nameOrID := range strings.Split(m, ",") {
if nameOrID = strings.TrimSpace(nameOrID); nameOrID != "" {
machines = append(machines, nameOrID)
}
}
}
machines := cli.ExpandCommaSeparatedValues(opts.machines)
filter = &api.VolumeFilter{
Machines: machines,
}
+1 -11
View File
@@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"strings"
"github.com/psviderski/uncloud/internal/cli"
"github.com/psviderski/uncloud/pkg/api"
@@ -60,16 +59,7 @@ func remove(ctx context.Context, uncli *cli.CLI, names []string, opts removeOpti
}
if len(opts.machines) > 0 {
// Expand comma-separated machine names.
var machines []string
for _, m := range opts.machines {
for _, nameOrID := range strings.Split(m, ",") {
if nameOrID = strings.TrimSpace(nameOrID); nameOrID != "" {
machines = append(machines, nameOrID)
}
}
}
machines := cli.ExpandCommaSeparatedValues(opts.machines)
filter.Machines = machines
}