Skip to content

Commit f66b2f6

Browse files
authored
Merge pull request #22547 from Homebrew/hide-maintainer-commands-manpage
Hide maintainer commands
2 parents 216b511 + e2dc82e commit f66b2f6

27 files changed

Lines changed: 407 additions & 696 deletions

Library/Homebrew/commands.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ def self.rebuild_internal_commands_completion_list
211211
require "completions"
212212

213213
cmds = internal_commands + internal_developer_commands
214-
cmds.reject! { |cmd| Homebrew::Completions::COMPLETIONS_EXCLUSION_LIST.include? cmd }
214+
cmds.reject! do |cmd|
215+
Homebrew::Completions::COMPLETIONS_EXCLUSION_LIST.include?(cmd) ||
216+
Homebrew::Completions.command_hidden_from_manpage?(cmd)
217+
end
215218

216219
file = HOMEBREW_REPOSITORY/"completions/internal_commands_list.txt"
217220
file.atomic_write("#{cmds.sort.join("\n")}\n")
@@ -225,6 +228,7 @@ def self.rebuild_commands_completion_list
225228
HOMEBREW_CACHE.mkpath
226229

227230
cmds = commands - Homebrew::Completions::COMPLETIONS_EXCLUSION_LIST
231+
cmds.reject! { |cmd| Homebrew::Completions.command_hidden_from_manpage?(cmd) }
228232

229233
all_commands_file = HOMEBREW_CACHE/"all_commands_list.txt"
230234
external_commands_file = HOMEBREW_CACHE/"external_commands_list.txt"

Library/Homebrew/completions.rb

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/^-+/, "")}"

Library/Homebrew/completions/bash.erb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ __brew_complete_commands() {
113113

114114
local cur="${COMP_WORDS[COMP_CWORD]}"
115115
local cmds
116+
local maintainer_cmds
116117

117118
if [[ -n ${__HOMEBREW_COMMANDS} ]]
118119
then
@@ -124,11 +125,15 @@ __brew_complete_commands() {
124125
then
125126
cmds="$(< "${HOMEBREW_REPOSITORY}/completions/internal_commands_list.txt")"
126127
fi
128+
if [[ -n ${HOMEBREW_DEVELOPER:-} ]]
129+
then
130+
maintainer_cmds="<%= maintainer_commands.join(" ") %>"
131+
fi
127132
while read -r line
128133
do
129134
[[ $(__brew_internal_command_alias "${line}") == "${line}" ]] || continue
130135
COMPREPLY+=("${line}")
131-
done < <(compgen -W "${cmds}" -- "${cur}")
136+
done < <(compgen -W "${cmds} ${maintainer_cmds}" -- "${cur}")
132137
export __HOMEBREW_COMMANDS=${cmds}
133138
}
134139

Library/Homebrew/completions/zsh.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ __brew_internal_commands() {
132132
commands=(
133133
<%= builtin_command_descriptions.join("\n ") + "\n" %>
134134
)
135+
if [[ -n ${HOMEBREW_DEVELOPER:-} ]]; then
136+
commands+=(
137+
<%= maintainer_descriptions.join("\n ") + "\n" %>
138+
)
139+
fi
135140
_describe -t internal-commands 'internal commands' commands
136141
}
137142

Library/Homebrew/dev-cmd/dispatch-build-bottle.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class DispatchBuildBottle < AbstractCommand
3535
conflicts "--linux", "--linux-self-hosted"
3636

3737
named_args :formula, min: 1
38+
39+
hide_from_man_page!
3840
end
3941

4042
sig { override.void }

Library/Homebrew/dev-cmd/formula-analytics.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class FormulaAnalytics < AbstractCommand
5454
conflicts "--json", "--all-core-formulae-json", "--setup"
5555

5656
named_args :none
57+
58+
hide_from_man_page!
5759
end
5860

5961
FIRST_INFLUXDB_ANALYTICS_DATE = T.let(Date.new(2023, 03, 27).freeze, Date)

Library/Homebrew/dev-cmd/generate-analytics-api.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class GenerateAnalyticsApi < AbstractCommand
2727
EOS
2828

2929
named_args :none
30+
31+
hide_from_man_page!
3032
end
3133

3234
sig { params(category_name: String, data_source: T.nilable(String)).returns(String) }

Library/Homebrew/dev-cmd/generate-cask-api.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class GenerateCaskApi < AbstractCommand
2525
description: "Generate API data without writing it to files."
2626

2727
named_args :none
28+
29+
hide_from_man_page!
2830
end
2931

3032
sig { override.void }

Library/Homebrew/dev-cmd/generate-formula-api.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class GenerateFormulaApi < AbstractCommand
2626
description: "Generate API data without writing it to files."
2727

2828
named_args :none
29+
30+
hide_from_man_page!
2931
end
3032

3133
sig { override.void }

Library/Homebrew/dev-cmd/generate-internal-api.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class GenerateInternalApi < AbstractCommand
2020
description: "Generate internal API data without writing it to files."
2121

2222
named_args :none
23+
24+
hide_from_man_page!
2325
end
2426

2527
sig { override.void }

0 commit comments

Comments
 (0)