commands: Use CLI::Parser to parse args

This commit is contained in:
Gautham Goli 2019-01-20 20:42:15 +05:30
parent 70c5b6f804
commit c5f01f203a
No known key found for this signature in database
GPG Key ID: 6A9ABBC284468364

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