From c5f01f203a6ad117c3eb2e60548d75e2c65fc304 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sun, 20 Jan 2019 20:42:15 +0530 Subject: [PATCH] commands: Use CLI::Parser to parse args --- Library/Homebrew/cmd/commands.rb | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/commands.rb b/Library/Homebrew/cmd/commands.rb index 9644a1dee2..adb29038a1 100644 --- a/Library/Homebrew/cmd/commands.rb +++ b/Library/Homebrew/cmd/commands.rb @@ -4,15 +4,36 @@ #: If `--quiet` is passed, list only the names of commands without the header. #: With `--include-aliases`, the aliases of internal commands will be included. +require "cli_parser" + module Homebrew module_function + def commands_args + Homebrew::CLI::Parser.new do + usage_banner <<~EOS + `commands` [] + + 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 - if ARGV.include? "--quiet" + commands_args.parse + + if args.quiet? cmds = internal_commands cmds += external_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) return end