diff --git a/internal/cmd/base/base.go b/internal/cmd/base/base.go index bfdff9f..9a8adf5 100644 --- a/internal/cmd/base/base.go +++ b/internal/cmd/base/base.go @@ -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 + } +} diff --git a/internal/cmd/groups/delete.go b/internal/cmd/groups/delete.go index 6fa710b..7edf450 100644 --- a/internal/cmd/groups/delete.go +++ b/internal/cmd/groups/delete.go @@ -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 } diff --git a/internal/cmd/groups/get.go b/internal/cmd/groups/get.go index 6c0f006..b716307 100644 --- a/internal/cmd/groups/get.go +++ b/internal/cmd/groups/get.go @@ -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 } diff --git a/internal/cmd/groups/list.go b/internal/cmd/groups/list.go index 2190048..92e17d7 100644 --- a/internal/cmd/groups/list.go +++ b/internal/cmd/groups/list.go @@ -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 } diff --git a/internal/cmd/groups/member_add.go b/internal/cmd/groups/member_add.go index 6e96ce6..f93058c 100644 --- a/internal/cmd/groups/member_add.go +++ b/internal/cmd/groups/member_add.go @@ -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 } diff --git a/internal/cmd/groups/member_remove.go b/internal/cmd/groups/member_remove.go index b2f68d6..96f8d61 100644 --- a/internal/cmd/groups/member_remove.go +++ b/internal/cmd/groups/member_remove.go @@ -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 } diff --git a/internal/cmd/groups/members.go b/internal/cmd/groups/members.go index 9d55da7..e90d1a8 100644 --- a/internal/cmd/groups/members.go +++ b/internal/cmd/groups/members.go @@ -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 } diff --git a/internal/cmd/groups/update.go b/internal/cmd/groups/update.go index e2647ef..e796a74 100644 --- a/internal/cmd/groups/update.go +++ b/internal/cmd/groups/update.go @@ -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 } diff --git a/internal/cmd/groups/zone_add.go b/internal/cmd/groups/zone_add.go index f0e02d6..94f8e83 100644 --- a/internal/cmd/groups/zone_add.go +++ b/internal/cmd/groups/zone_add.go @@ -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 } diff --git a/internal/cmd/groups/zone_remove.go b/internal/cmd/groups/zone_remove.go index f171c0e..97c77bf 100644 --- a/internal/cmd/groups/zone_remove.go +++ b/internal/cmd/groups/zone_remove.go @@ -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 } diff --git a/internal/cmd/permission_templates/delete.go b/internal/cmd/permission_templates/delete.go index 30ff03f..c4ae745 100644 --- a/internal/cmd/permission_templates/delete.go +++ b/internal/cmd/permission_templates/delete.go @@ -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 } diff --git a/internal/cmd/permission_templates/get.go b/internal/cmd/permission_templates/get.go index 45bc10f..0fa85da 100644 --- a/internal/cmd/permission_templates/get.go +++ b/internal/cmd/permission_templates/get.go @@ -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 } diff --git a/internal/cmd/permission_templates/update.go b/internal/cmd/permission_templates/update.go index d1ed026..ad1e6ba 100644 --- a/internal/cmd/permission_templates/update.go +++ b/internal/cmd/permission_templates/update.go @@ -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 }