@@ -15,6 +15,8 @@ module Completions
1515 :aliases ,
1616 :builtin_command_descriptions ,
1717 :completion_functions ,
18+ :maintainer_descriptions ,
19+ :maintainer_commands ,
1820 :function_mappings ,
1921 )
2022
@@ -125,7 +127,10 @@ def self.show_completions_message_if_needed
125127
126128 sig { void }
127129 def self . update_shell_completions!
128- commands = Commands . commands ( external : false ) . sort
130+ commands = ( Commands . internal_commands_paths + Commands . internal_developer_commands_paths )
131+ . map { |path | Commands . basename_without_extension ( path ) }
132+ . uniq
133+ . sort
129134
130135 puts "Writing completions to #{ COMPLETIONS_DIR } "
131136
@@ -139,6 +144,21 @@ def self.command_gets_completions?(command)
139144 command_options ( command ) . any? || Commands . command_subcommands ( command ) . any?
140145 end
141146
147+ sig { params ( command : String ) . returns ( T ::Boolean ) }
148+ def self . command_hidden_from_manpage? ( command )
149+ return false unless ( cmd_path = Commands . path ( command ) )
150+
151+ Homebrew ::CLI ::Parser . from_cmd_path ( cmd_path ) &.hide_from_man_page == true
152+ end
153+
154+ sig { params ( command : String ) . returns ( T . nilable ( String ) ) }
155+ def self . zsh_command_description ( command )
156+ description = Commands . command_description ( command , short : true )
157+ return if description . blank?
158+
159+ "'#{ command } :#{ format_description ( description ) } '"
160+ end
161+
142162 sig { params ( subcommands : T ::Array [ Homebrew ::CLI ::Parser ::Subcommand ] ) . returns ( T ::Array [ String ] ) }
143163 def self . subcommand_completion_names ( subcommands )
144164 subcommands . flat_map { |subcommand | [ subcommand . name , *subcommand . aliases ] }
@@ -293,6 +313,7 @@ def self.generate_bash_completion_file(commands)
293313 completion_functions : commands . filter_map do |command |
294314 generate_bash_subcommand_completion command
295315 end ,
316+ maintainer_commands : commands . select { |command | command_hidden_from_manpage? ( command ) } ,
296317 function_mappings : commands . filter_map do |command |
297318 next unless command_gets_completions? command
298319
@@ -466,12 +487,15 @@ def self.generate_zsh_completion_file(commands)
466487
467488 builtin_command_descriptions : commands . filter_map do |command |
468489 next if Commands ::HOMEBREW_INTERNAL_COMMAND_ALIASES . key? command
490+ next if command_hidden_from_manpage? ( command )
491+
492+ zsh_command_description ( command )
493+ end ,
469494
470- description = Commands . command_description ( command , short : true )
471- next if description . blank?
495+ maintainer_descriptions : commands . filter_map do | command |
496+ next unless command_hidden_from_manpage? ( command )
472497
473- description = format_description description
474- "'#{ command } :#{ description } '"
498+ zsh_command_description ( command )
475499 end ,
476500
477501 completion_functions : commands . filter_map do |command |
@@ -484,18 +508,20 @@ def self.generate_zsh_completion_file(commands)
484508
485509 sig { params ( command : String ) . returns ( T . nilable ( String ) ) }
486510 def self . generate_fish_subcommand_completion ( command )
487- return unless command_gets_completions? command
488-
489- subcommands = Commands . command_subcommands ( command )
490- return generate_fish_nested_subcommand_completion ( command , subcommands ) if subcommands . present?
491-
492511 command_description = format_description Commands . command_description ( command , short : true ) . to_s , fish : true
493512 lines = if COMPLETIONS_EXCLUSION_LIST . include? ( command ) ||
494513 Commands ::HOMEBREW_INTERNAL_COMMAND_ALIASES . key? ( command )
495514 [ ]
515+ elsif command_hidden_from_manpage? ( command )
516+ [ "complete -f -c brew -n 'not __fish_brew_command; and set -q HOMEBREW_DEVELOPER' " \
517+ "-a '#{ command } ' -d '#{ command_description } '" ]
496518 else
497519 [ "__fish_brew_complete_cmd '#{ command } ' '#{ command_description } '" ]
498520 end
521+ return unless command_gets_completions? command
522+
523+ subcommands = Commands . command_subcommands ( command )
524+ return generate_fish_nested_subcommand_completion ( command , subcommands ) if subcommands . present?
499525
500526 options = command_options ( command ) . sort . filter_map do |opt , desc |
501527 arg_line = "__fish_brew_complete_arg '#{ command } ' -l #{ opt . sub ( /^-+/ , "" ) } "
0 commit comments