Skip to content

Commit

Permalink
Add rack completion for machine ls. (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Jun 6, 2024
1 parent f9c3071 commit 74f0197
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
21 changes: 21 additions & 0 deletions cmd/completion/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,24 @@ func (c *Completion) IssueSeverityCompletion(cmd *cobra.Command, args []string,

return names, cobra.ShellCompDirectiveNoFileComp
}

func (c *Completion) MachineRackListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
mfr := &models.V1MachineFindRequest{}

if cmd.Flag("partition") != nil {
if partition := cmd.Flag("partition").Value.String(); partition != "" {
mfr.PartitionID = partition
}
}

resp, err := c.client.Machine().FindMachines(machine.NewFindMachinesParams().WithBody(mfr), nil)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, m := range resp.Payload {
names = append(names, m.Rackid)
}

return names, cobra.ShellCompDirectiveNoFileComp
}
1 change: 1 addition & 0 deletions cmd/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (c *machineCmd) listCmdFlags(cmd *cobra.Command, lastEventErrorThresholdDef
{flagName: "partition", f: c.comp.PartitionListCompletion},
{flagName: "size", f: c.comp.SizeListCompletion},
{flagName: "project", f: c.comp.ProjectListCompletion},
{flagName: "rack", f: c.comp.MachineRackListCompletion},
{flagName: "id", f: c.comp.MachineListCompletion},
{flagName: "image", f: c.comp.ImageListCompletion},
{flagName: "state", f: cobra.FixedCompletions([]string{
Expand Down
2 changes: 1 addition & 1 deletion cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func newProjectCmd(c *config) *cobra.Command {

cmdsConfig := &genericcli.CmdsConfig[*models.V1ProjectCreateRequest, *models.V1ProjectUpdateRequest, *models.V1ProjectResponse]{
BinaryName: binaryName,
GenericCLI: genericcli.NewGenericCLI[*models.V1ProjectCreateRequest, *models.V1ProjectUpdateRequest, *models.V1ProjectResponse](w).WithFS(c.fs),
GenericCLI: genericcli.NewGenericCLI(w).WithFS(c.fs),
Singular: "project",
Plural: "projects",
Description: "a project belongs to a tenant and groups together entities in metal-stack.",
Expand Down
4 changes: 3 additions & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func Test_BasicRootCmdStuff(t *testing.T) {
_, err := w.Write(mustMarshal(t, &models.RestHealthResponse{
Status: pointer.Pointer(string(rest.HealthStatusHealthy)),
}))
require.NoError(t, err)
if err != nil {
t.Errorf("error writing response: %s", err)
}
}))
defer ts.Close()

Expand Down

0 comments on commit 74f0197

Please sign in to comment.