brew/Library/Homebrew/cmd/commands.rb

55 lines
1.3 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
2019-04-17 18:25:08 +09:00
require "cli/parser"
module Homebrew
2020-10-20 12:03:48 +02:00
extend T::Sig
2016-09-26 01:44:51 +02:00
module_function
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
def commands_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`commands` [<options>]
Show lists of built-in and external commands.
EOS
2020-07-30 18:40:10 +02:00
switch "-q", "--quiet",
description: "List only the names of commands without category headers."
switch "--include-aliases",
2019-04-30 08:44:35 +01:00
depends_on: "--quiet",
description: "Include aliases of internal commands."
2020-07-30 18:40:10 +02:00
2021-01-10 14:26:40 -05:00
named_args :none
end
end
def commands
2020-07-30 18:40:10 +02:00
args = commands_args.parse
if args.quiet?
puts Formatter.columns(Commands.commands(aliases: args.include_aliases?))
return
end
prepend_separator = false
2020-07-22 22:45:47 -04:00
{
"Built-in commands" => Commands.internal_commands,
"Built-in developer commands" => Commands.internal_developer_commands,
"External commands" => Commands.external_commands,
"Cask commands" => Commands.cask_internal_commands,
"External cask commands" => Commands.cask_external_commands,
}.each do |title, commands|
2020-07-26 22:12:08 -04:00
next if commands.blank?
puts if prepend_separator
ohai title, Formatter.columns(commands)
prepend_separator ||= true
2020-07-20 13:18:09 -04:00
end
end
end