Port Homebrew::Cmd::CommandsCmd

This commit is contained in:
Douglas Eichelberger 2024-03-29 16:25:28 -07:00
parent adf47bb11b
commit 02e2772e9d
2 changed files with 33 additions and 38 deletions

View File

@ -1,49 +1,46 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "cli/parser" require "abstract_command"
module Homebrew module Homebrew
module_function module Cmd
class CommandsCmd < AbstractCommand
cmd_args do
description <<~EOS
Show lists of built-in and external commands.
EOS
switch "-q", "--quiet",
description: "List only the names of commands without category headers."
switch "--include-aliases",
depends_on: "--quiet",
description: "Include aliases of internal commands."
sig { returns(CLI::Parser) } named_args :none
def commands_args end
Homebrew::CLI::Parser.new do
description <<~EOS
Show lists of built-in and external commands.
EOS
switch "-q", "--quiet",
description: "List only the names of commands without category headers."
switch "--include-aliases",
depends_on: "--quiet",
description: "Include aliases of internal commands."
named_args :none sig { override.void }
end def run
end if args.quiet?
puts Formatter.columns(Commands.commands(aliases: args.include_aliases?))
return
end
sig { void } prepend_separator = T.let(false, T::Boolean)
def commands
args = commands_args.parse
if args.quiet? {
puts Formatter.columns(Commands.commands(aliases: args.include_aliases?)) "Built-in commands" => Commands.internal_commands,
return "Built-in developer commands" => Commands.internal_developer_commands,
end "External commands" => Commands.external_commands,
}.each do |title, commands|
next if commands.blank?
prepend_separator = T.let(false, T::Boolean) puts if prepend_separator
ohai title, Formatter.columns(commands)
{ prepend_separator ||= true
"Built-in commands" => Commands.internal_commands, end
"Built-in developer commands" => Commands.internal_developer_commands, end
"External commands" => Commands.external_commands,
}.each do |title, commands|
next if commands.blank?
puts if prepend_separator
ohai title, Formatter.columns(commands)
prepend_separator ||= true
end end
end end
end end

View File

@ -1,11 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cmd/commands" require "cmd/commands"
require "fileutils"
require "cmd/shared_examples/args_parse" require "cmd/shared_examples/args_parse"
RSpec.describe "brew commands" do RSpec.describe Homebrew::Cmd::CommandsCmd do
it_behaves_like "parseable arguments" it_behaves_like "parseable arguments"
it "prints a list of all available commands", :integration_test do it "prints a list of all available commands", :integration_test do