From 02e2772e9d2c415ef4198983872a205c8ecccadf Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Fri, 29 Mar 2024 16:25:28 -0700 Subject: [PATCH] Port Homebrew::Cmd::CommandsCmd --- Library/Homebrew/cmd/commands.rb | 67 +++++++++++----------- Library/Homebrew/test/cmd/commands_spec.rb | 4 +- 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/Library/Homebrew/cmd/commands.rb b/Library/Homebrew/cmd/commands.rb index f28546ade6..6ec4cf889e 100644 --- a/Library/Homebrew/cmd/commands.rb +++ b/Library/Homebrew/cmd/commands.rb @@ -1,49 +1,46 @@ # typed: strict # frozen_string_literal: true -require "cli/parser" +require "abstract_command" 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) } - def commands_args - 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 + end - named_args :none - end - end + sig { override.void } + def run + if args.quiet? + puts Formatter.columns(Commands.commands(aliases: args.include_aliases?)) + return + end - sig { void } - def commands - args = commands_args.parse + prepend_separator = T.let(false, T::Boolean) - if args.quiet? - puts Formatter.columns(Commands.commands(aliases: args.include_aliases?)) - return - end + { + "Built-in commands" => Commands.internal_commands, + "Built-in developer commands" => Commands.internal_developer_commands, + "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) - { - "Built-in commands" => Commands.internal_commands, - "Built-in developer commands" => Commands.internal_developer_commands, - "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 + prepend_separator ||= true + end + end end end end diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index b49068378d..9f7de67f11 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -1,11 +1,9 @@ # frozen_string_literal: true require "cmd/commands" -require "fileutils" - require "cmd/shared_examples/args_parse" -RSpec.describe "brew commands" do +RSpec.describe Homebrew::Cmd::CommandsCmd do it_behaves_like "parseable arguments" it "prints a list of all available commands", :integration_test do