Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions internal/cmd/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,25 @@ func GroupNameCompletion(s *state.State) func(*cobra.Command, []string, string)
return names, cobra.ShellCompDirectiveNoFileComp
}
}

// PermissionTemplateNameCompletion returns a Cobra completion function that
// fetches permission template names from the Poweradmin API.
func PermissionTemplateNameCompletion(s *state.State) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
client, err := s.Client()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
templates, _, err := client.PermissionTemplate.List(cmd.Context())
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, t := range templates {
if strings.HasPrefix(t.Name, toComplete) {
names = append(names, t.Name)
}
}
return names, cobra.ShellCompDirectiveNoFileComp
}
}
2 changes: 1 addition & 1 deletion internal/cmd/groups/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ func NewDeleteCmd(s *state.State) *cobra.Command {
cmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt")
cmd.Flags().BoolP("quiet", "q", false, "Suppress output after deletion")
// Register shell completion for --name flag.
cmd.RegisterFlagCompletionFunc("name", base.ZoneNameCompletion(s))
cmd.RegisterFlagCompletionFunc("name", base.GroupNameCompletion(s))
return cmd
}
2 changes: 1 addition & 1 deletion internal/cmd/groups/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ func NewGetCmd(s *state.State) *cobra.Command {
cmd.Flags().String("id", "", "Group ID")
cmd.Flags().StringP("output", "o", "table", "Output format. One of: table|json")
// Register shell completion for --name flag.
cmd.RegisterFlagCompletionFunc("name", base.ZoneNameCompletion(s))
cmd.RegisterFlagCompletionFunc("name", base.GroupNameCompletion(s))
return cmd
}
2 changes: 1 addition & 1 deletion internal/cmd/groups/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ func NewListCmd(s *state.State) *cobra.Command {
cmd.Flags().StringP("output", "o", "table", "Output format. One of: table|json")
cmd.Flags().Bool("no-header", false, "Suppress table header row")
// Register shell completion for --name flag.
cmd.RegisterFlagCompletionFunc("name", base.ZoneNameCompletion(s))
cmd.RegisterFlagCompletionFunc("name", base.GroupNameCompletion(s))
return cmd
}
2 changes: 1 addition & 1 deletion internal/cmd/groups/member_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ func NewMemberAddCmd(s *state.State) *cobra.Command {
cmd.Flags().String("group-id", "", "Group ID (required)")
cmd.Flags().String("user-id", "", "User ID to add (required)")
// Register shell completion for --name flag.
cmd.RegisterFlagCompletionFunc("name", base.ZoneNameCompletion(s))
cmd.RegisterFlagCompletionFunc("name", base.GroupNameCompletion(s))
return cmd
}
2 changes: 1 addition & 1 deletion internal/cmd/groups/member_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ func NewMemberRemoveCmd(s *state.State) *cobra.Command {
cmd.Flags().String("group-id", "", "Group ID (required)")
cmd.Flags().String("user-id", "", "User ID to remove (required)")
// Register shell completion for --name flag.
cmd.RegisterFlagCompletionFunc("name", base.ZoneNameCompletion(s))
cmd.RegisterFlagCompletionFunc("name", base.GroupNameCompletion(s))
return cmd
}
2 changes: 1 addition & 1 deletion internal/cmd/groups/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewMembersCmd(s *state.State) *cobra.Command {
cmd.Flags().StringP("output", "o", "table", "Output format. One of: table|json")
cmd.Flags().Bool("no-header", false, "Suppress table header row")
// Register shell completion for --name flag.
cmd.RegisterFlagCompletionFunc("name", base.ZoneNameCompletion(s))
cmd.RegisterFlagCompletionFunc("name", base.GroupNameCompletion(s))

return cmd
}
2 changes: 1 addition & 1 deletion internal/cmd/groups/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ func NewUpdateCmd(s *state.State) *cobra.Command {
cmd.Flags().String("description", "", "New description")
cmd.Flags().StringP("output", "o", "table", "Output format. One of: table|json")
// Register shell completion for --name flag.
cmd.RegisterFlagCompletionFunc("name", base.ZoneNameCompletion(s))
cmd.RegisterFlagCompletionFunc("name", base.GroupNameCompletion(s))
return cmd
}
2 changes: 1 addition & 1 deletion internal/cmd/groups/zone_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ func NewZoneAddCmd(s *state.State) *cobra.Command {
cmd.Flags().String("group-id", "", "Group ID (required)")
cmd.Flags().String("zone-id", "", "Zone ID to add (required)")
// Register shell completion for --name flag.
cmd.RegisterFlagCompletionFunc("name", base.ZoneNameCompletion(s))
cmd.RegisterFlagCompletionFunc("name", base.GroupNameCompletion(s))
return cmd
}
2 changes: 1 addition & 1 deletion internal/cmd/groups/zone_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ func NewZoneRemoveCmd(s *state.State) *cobra.Command {
cmd.Flags().String("group-id", "", "Group ID (required)")
cmd.Flags().String("zone-id", "", "Zone ID to remove (required)")
// Register shell completion for --name flag.
cmd.RegisterFlagCompletionFunc("name", base.ZoneNameCompletion(s))
cmd.RegisterFlagCompletionFunc("name", base.GroupNameCompletion(s))
return cmd
}
1 change: 1 addition & 0 deletions internal/cmd/permission_templates/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ func NewDeleteCmd(s *state.State) *cobra.Command {
cmd.Flags().StringP("output", "o", "table", "Output format. One of: table|json")
cmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt")
cmd.Flags().BoolP("quiet", "q", false, "Suppress output after deletion")
cmd.RegisterFlagCompletionFunc("name", base.PermissionTemplateNameCompletion(s))
return cmd
}
1 change: 1 addition & 0 deletions internal/cmd/permission_templates/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ func NewGetCmd(s *state.State) *cobra.Command {
cmd.Flags().String("name", "", "Permission template name")
cmd.Flags().String("id", "", "Permission template ID")
cmd.Flags().StringP("output", "o", "table", "Output format. One of: table|json")
cmd.RegisterFlagCompletionFunc("name", base.PermissionTemplateNameCompletion(s))
return cmd
}
1 change: 1 addition & 0 deletions internal/cmd/permission_templates/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,6 @@ func NewUpdateCmd(s *state.State) *cobra.Command {
cmd.Flags().String("type", "", "New template type. One of: user|group")
cmd.Flags().StringSlice("permissions", []string{}, "New permission IDs (replaces existing)")
cmd.Flags().StringP("output", "o", "table", "Output format. One of: table|json")
cmd.RegisterFlagCompletionFunc("name", base.PermissionTemplateNameCompletion(s))
return cmd
}
Loading