Merge pull request #5568 from GauthamGoli/commands-args

commands: Use CLI::Parser to parse args
This commit is contained in:
Gautham Goli 2019-01-22 18:59:01 +05:30 committed by GitHub
commit 4cf2bd2269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,15 +4,36 @@
#: If `--quiet` is passed, list only the names of commands without the header. #: If `--quiet` is passed, list only the names of commands without the header.
#: With `--include-aliases`, the aliases of internal commands will be included. #: With `--include-aliases`, the aliases of internal commands will be included.
require "cli_parser"
module Homebrew module Homebrew
module_function module_function
def commands_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`commands` [<options>]
Show a list of built-in and external commands.
EOS
switch "--quiet",
description: "List only the names of commands without the header."
switch "--include-aliases",
depends_on: "--quiet",
description: "Include the aliases of internal commands."
switch :verbose
switch :debug
end
end
def commands def commands
if ARGV.include? "--quiet" commands_args.parse
if args.quiet?
cmds = internal_commands cmds = internal_commands
cmds += external_commands cmds += external_commands
cmds += internal_developer_commands cmds += internal_developer_commands
cmds += HOMEBREW_INTERNAL_COMMAND_ALIASES.keys if ARGV.include? "--include-aliases" cmds += HOMEBREW_INTERNAL_COMMAND_ALIASES.keys if args.include_aliases?
puts Formatter.columns(cmds.sort) puts Formatter.columns(cmds.sort)
return return
end end