Skip to content
2 changes: 1 addition & 1 deletion cmd/admin/v2/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newAuditCmd(c *config.Config) *cobra.Command {
cmd.Flags().Bool("prettify-body", true, "attempts to interpret the body as json and prettifies it.")

genericcli.Must(cmd.RegisterFlagCompletionFunc("phase", c.Completion.AuditPhase))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
genericcli.Must(cmd.RegisterFlagCompletionFunc("tenant", c.Completion.Tenant))
genericcli.Must(cmd.RegisterFlagCompletionFunc("result-code", c.Completion.AuditStatusCodes))
},
Expand Down
6 changes: 3 additions & 3 deletions cmd/admin/v2/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newNetworkCmd(c *config.Config) *cobra.Command {
cmd.Flags().StringP("type", "t", "", "type of the network. [optional]")
cmd.Flags().String("nat-type", "", "nat type of the network. [optional]")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
genericcli.Must(cmd.RegisterFlagCompletionFunc("partition", c.Completion.Partition))
genericcli.Must(cmd.RegisterFlagCompletionFunc("addressfamily", c.Completion.NetworkAddressFamily))
genericcli.Must(cmd.RegisterFlagCompletionFunc("type", c.Completion.NetworkType))
Expand Down Expand Up @@ -79,7 +79,7 @@ func newNetworkCmd(c *config.Config) *cobra.Command {
cmd.Flags().StringSlice("destination-prefixes", nil, "destination-prefixes for this network. [optional]")
cmd.Flags().StringSlice("additional-announcable-cidrs", nil, "additional-announcable-cidrs for this network. [optional]")
cmd.Flags().Uint32("vrf", 0, "the vrf of the network to create. [optional]")
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
genericcli.Must(cmd.RegisterFlagCompletionFunc("partition", c.Completion.Partition))
genericcli.Must(cmd.RegisterFlagCompletionFunc("addressfamily", c.Completion.NetworkAddressFamily))
genericcli.Must(cmd.RegisterFlagCompletionFunc("type", c.Completion.NetworkType))
Expand All @@ -99,7 +99,7 @@ func newNetworkCmd(c *config.Config) *cobra.Command {
cmd.Flags().StringSlice("add-labels", nil, "labels to add to the network")
cmd.Flags().StringSlice("remove-labels", nil, "labels to remove to the network")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/admin/v2/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func newPartitionCmd(c *config.Config) *cobra.Command {
capacityCmd.Flags().StringP("project", "", "", "consider project-specific counts, e.g. size reservations.")
capacityCmd.Flags().StringSlice("sort-by", []string{}, fmt.Sprintf("order by (comma separated) column(s), sort direction can be changed by appending :asc or :desc behind the column identifier. possible values: %s", strings.Join(sorters.PartitionCapacitySorter().AvailableKeys(), "|")))
genericcli.Must(capacityCmd.RegisterFlagCompletionFunc("id", c.Completion.Partition))
genericcli.Must(capacityCmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(capacityCmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
genericcli.Must(capacityCmd.RegisterFlagCompletionFunc("size", c.Completion.Size))
genericcli.Must(capacityCmd.RegisterFlagCompletionFunc("sort-by", cobra.FixedCompletions(sorters.PartitionCapacitySorter().AvailableKeys(), cobra.ShellCompDirectiveNoFileComp)))

Expand Down
8 changes: 4 additions & 4 deletions cmd/admin/v2/vpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func newVPNCmd(c *config.Config) *cobra.Command {
ListPrinter: func() printers.Printer { return c.ListPrinter },
ListCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().String("project", "", "the project for which vpn nodes should be listed")
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
},
OnlyCmds: genericcli.OnlyCmds(genericcli.ListCmd),
ValidArgsFn: w.c.Completion.ProjectList,
ValidArgsFn: w.c.Completion.Project,
}

authKeyCmd := &cobra.Command{
Expand All @@ -49,14 +49,14 @@ func newVPNCmd(c *config.Config) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
return w.authKey()
},
ValidArgsFunction: c.Completion.ProjectList,
ValidArgsFunction: c.Completion.Project,
}
authKeyCmd.Flags().String("project", "", "the project for which the authkey should be generated")
authKeyCmd.Flags().String("reason", "", "the reason why the authkey should be generated")
authKeyCmd.Flags().Bool("ephemeral", true, "ephemeral defines if the key can only be used once")
authKeyCmd.Flags().Duration("expires", 1*time.Hour, "the duration after the generated key is not valid anymore")
genericcli.Must(authKeyCmd.MarkFlagRequired("project"))
genericcli.Must(authKeyCmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(authKeyCmd.RegisterFlagCompletionFunc("project", c.Completion.Project))

return genericcli.NewCmds(cmdsConfig, authKeyCmd)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/v2/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func newAuditCmd(c *config.Config) *cobra.Command {
cmd.Flags().Bool("prettify-body", true, "attempts to interpret the body as json and prettifies it.")

genericcli.Must(cmd.RegisterFlagCompletionFunc("phase", c.Completion.AuditPhase))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
genericcli.Must(cmd.RegisterFlagCompletionFunc("tenant", c.Completion.Tenant))
genericcli.Must(cmd.RegisterFlagCompletionFunc("result-code", c.Completion.AuditStatusCodes))
},
Expand Down
10 changes: 5 additions & 5 deletions cmd/api/v2/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func newIPCmd(c *config.Config) *cobra.Command {
ListCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().StringP("project", "p", "", "project from where ips should be listed")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
},
CreateCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().StringP("project", "p", "", "project of the ip")
Expand All @@ -45,7 +45,7 @@ func newIPCmd(c *config.Config) *cobra.Command {
cmd.Flags().BoolP("static", "", false, "make this ip static")
cmd.Flags().StringP("addressfamily", "", "", "addressfamily, can be either IPv4|IPv6, defaults to IPv4 (optional)")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
},
UpdateCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().StringP("project", "p", "", "project of the ip")
Expand All @@ -55,17 +55,17 @@ func newIPCmd(c *config.Config) *cobra.Command {
cmd.Flags().StringArray("remove-labels", nil, "removes the volume labels with the given key")
cmd.Flags().Bool("static", false, "make this ip static")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
},
DescribeCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().StringP("project", "p", "", "project of the ip")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
},
DeleteCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().StringP("project", "p", "", "project of the ip")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
},
CreateRequestFromCLI: w.createFromCLI,
UpdateRequestFromCLI: w.updateFromCLI,
Expand Down
8 changes: 4 additions & 4 deletions cmd/api/v2/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func newNetworkCmd(c *config.Config) *cobra.Command {
cmd.Flags().StringP("type", "t", "", "type of the network. [optional]")

genericcli.Must(cmd.RegisterFlagCompletionFunc("id", c.Completion.Network))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
genericcli.Must(cmd.RegisterFlagCompletionFunc("partition", c.Completion.Partition))
genericcli.Must(cmd.RegisterFlagCompletionFunc("addressfamily", c.Completion.NetworkAddressFamily))
genericcli.Must(cmd.RegisterFlagCompletionFunc("type", c.Completion.NetworkType))
Expand Down Expand Up @@ -66,7 +66,7 @@ func newNetworkCmd(c *config.Config) *cobra.Command {
cmd.Flags().Uint32("ipv4-prefix-length", 0, "ipv4 prefix bit length of the network to create, defaults to default child prefix length of the parent network. [optional]")
cmd.Flags().Uint32("ipv6-prefix-length", 0, "ipv6 prefix bit length of the network to create, defaults to default child prefix length of the parent network. [optional]")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
genericcli.Must(cmd.RegisterFlagCompletionFunc("partition", c.Completion.Partition))
genericcli.Must(cmd.RegisterFlagCompletionFunc("addressfamily", c.Completion.NetworkAddressFamily))
genericcli.Must(cmd.RegisterFlagCompletionFunc("parent-network", c.Completion.Network))
Expand All @@ -84,11 +84,11 @@ func newNetworkCmd(c *config.Config) *cobra.Command {
cmd.Flags().StringSlice("add-labels", nil, "labels to add to the network")
cmd.Flags().StringSlice("remove-labels", nil, "labels to remove to the network")

genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
},
DeleteCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().String("project", "", "project of this network.")
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(cmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
},
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/api/v2/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func newProjectCmd(c *config.Config) *cobra.Command {
cmd.Flags().String("description", "", "the description of the project to update")
},
UpdateRequestFromCLI: w.updateRequestFromCLI,
ValidArgsFn: w.c.Completion.ProjectList,
ValidArgsFn: w.c.Completion.Project,
}

inviteCmd := &cobra.Command{
Expand All @@ -72,7 +72,7 @@ func newProjectCmd(c *config.Config) *cobra.Command {
generateInviteCmd.Flags().StringP("project", "p", "", "the project for which to generate the invite")
generateInviteCmd.Flags().String("role", apiv2.ProjectRole_PROJECT_ROLE_VIEWER.String(), "the role that the new member will assume when joining through the invite secret")

genericcli.Must(generateInviteCmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(generateInviteCmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
genericcli.Must(generateInviteCmd.RegisterFlagCompletionFunc("role", c.Completion.ProjectRole))

deleteInviteCmd := &cobra.Command{
Expand All @@ -87,7 +87,7 @@ func newProjectCmd(c *config.Config) *cobra.Command {

deleteInviteCmd.Flags().StringP("project", "p", "", "the project in which to delete the invite")

genericcli.Must(deleteInviteCmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(deleteInviteCmd.RegisterFlagCompletionFunc("project", c.Completion.Project))

listInvitesCmd := &cobra.Command{
Use: "list",
Expand All @@ -102,7 +102,7 @@ func newProjectCmd(c *config.Config) *cobra.Command {

genericcli.AddSortFlag(listInvitesCmd, sorters.ProjectInviteSorter())

genericcli.Must(listInvitesCmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(listInvitesCmd.RegisterFlagCompletionFunc("project", c.Completion.Project))

joinProjectCmd := &cobra.Command{
Use: "join <secret>",
Expand Down Expand Up @@ -145,7 +145,7 @@ func newProjectCmd(c *config.Config) *cobra.Command {

removeMemberCmd.Flags().StringP("project", "p", "", "the project in which to remove the member")

genericcli.Must(removeMemberCmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(removeMemberCmd.RegisterFlagCompletionFunc("project", c.Completion.Project))

updateMemberCmd := &cobra.Command{
Use: "update <member>",
Expand All @@ -159,7 +159,7 @@ func newProjectCmd(c *config.Config) *cobra.Command {
updateMemberCmd.Flags().StringP("project", "p", "", "the project in which to remove the member")
updateMemberCmd.Flags().String("role", "", "the role of the member")

genericcli.Must(updateMemberCmd.RegisterFlagCompletionFunc("project", c.Completion.ProjectList))
genericcli.Must(updateMemberCmd.RegisterFlagCompletionFunc("project", c.Completion.Project))
genericcli.Must(updateMemberCmd.RegisterFlagCompletionFunc("role", c.Completion.ProjectRole))

memberCmd.AddCommand(removeMemberCmd, updateMemberCmd, listMembersCmd)
Expand Down
14 changes: 9 additions & 5 deletions cmd/completion/completion.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package completion

import (
"context"

"github.com/metal-stack/api/go/client"
"github.com/spf13/cobra"
)

type Completion struct {
Client client.Client
Project string
Ctx context.Context
client client.Client
project string
}

func New(c client.Client, project string) *Completion {
return &Completion{
client: c,
project: project,
}
}

func OutputFormat(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/completion/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

func (c *Completion) Ip(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
req := &apiv2.IPServiceListRequest{
Project: c.Project,
Project: c.project,
}
resp, err := c.Client.Apiv2().IP().List(c.Ctx, req)
resp, err := c.client.Apiv2().IP().List(cmd.Context(), req)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/completion/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

func (c *Completion) Network(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ownNetworks, err := c.Client.Apiv2().Network().List(c.Ctx, &apiv2.NetworkServiceListRequest{
Project: c.Project,
ownNetworks, err := c.client.Apiv2().Network().List(cmd.Context(), &apiv2.NetworkServiceListRequest{
Project: c.project,
})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}

baseNetworks, err := c.Client.Apiv2().Network().ListBaseNetworks(c.Ctx, &apiv2.NetworkServiceListBaseNetworksRequest{
Project: c.Project,
baseNetworks, err := c.client.Apiv2().Network().ListBaseNetworks(cmd.Context(), &apiv2.NetworkServiceListBaseNetworksRequest{
Project: c.project,
})
if err != nil {
return nil, cobra.ShellCompDirectiveError
Expand Down Expand Up @@ -71,7 +71,7 @@ func (c *Completion) NetworkAddressFamily(cmd *cobra.Command, args []string, toC
}

func (c *Completion) NetworkAdmin(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
networks, err := c.Client.Adminv2().Network().List(c.Ctx, &adminv2.NetworkServiceListRequest{})
networks, err := c.client.Adminv2().Network().List(cmd.Context(), &adminv2.NetworkServiceListRequest{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/completion/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func (c *Completion) Partition(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
req := &apiv2.PartitionServiceListRequest{}
resp, err := c.Client.Apiv2().Partition().List(c.Ctx, req)
resp, err := c.client.Apiv2().Partition().List(cmd.Context(), req)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/completion/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
)

func (c *Completion) ProjectList(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
func (c *Completion) Project(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
req := &apiv2.ProjectServiceListRequest{}
resp, err := c.Client.Apiv2().Project().List(c.Ctx, req)
resp, err := c.client.Apiv2().Project().List(cmd.Context(), req)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down Expand Up @@ -36,8 +36,8 @@ func (c *Completion) ProjectRole(cmd *cobra.Command, args []string, toComplete s
}

func (c *Completion) ProjectInvite(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
resp, err := c.Client.Apiv2().Project().InvitesList(c.Ctx, &apiv2.ProjectServiceInvitesListRequest{
Project: c.Project,
resp, err := c.client.Apiv2().Project().InvitesList(cmd.Context(), &apiv2.ProjectServiceInvitesListRequest{
Project: c.project,
})
if err != nil {
return nil, cobra.ShellCompDirectiveError
Expand All @@ -53,8 +53,8 @@ func (c *Completion) ProjectInvite(cmd *cobra.Command, args []string, toComplete
}

func (c *Completion) ProjectMember(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
resp, err := c.Client.Apiv2().Project().Get(c.Ctx, &apiv2.ProjectServiceGetRequest{
Project: c.Project,
resp, err := c.client.Apiv2().Project().Get(cmd.Context(), &apiv2.ProjectServiceGetRequest{
Project: c.project,
})
if err != nil {
return nil, cobra.ShellCompDirectiveError
Expand Down
2 changes: 1 addition & 1 deletion cmd/completion/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func (c *Completion) Size(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
req := &apiv2.SizeServiceListRequest{}
resp, err := c.Client.Apiv2().Size().List(c.Ctx, req)
resp, err := c.client.Apiv2().Size().List(cmd.Context(), req)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down
Loading
Loading