diff --git a/Library/Homebrew/cmd/options.rb b/Library/Homebrew/cmd/options.rb index 397a39df0c66a6c671014bc0e7a5eb9295bedafc..c41d27f1497defcfb2e6e59cb45f0b22c1d7366c 100644 --- a/Library/Homebrew/cmd/options.rb +++ b/Library/Homebrew/cmd/options.rb @@ -3,6 +3,7 @@ require "formula" require "options" require "cli/parser" +require "commands" module Homebrew module_function @@ -20,8 +21,10 @@ module Homebrew description: "Show options for formulae that are currently installed." switch "--all", description: "Show options for all available formulae." + flag "--command=", + description: "Show options for the specified <command>." switch :debug - conflicts "--installed", "--all" + conflicts "--installed", "--all", "--command" end end @@ -32,6 +35,22 @@ module Homebrew puts_options Formula.to_a.sort elsif args.installed? puts_options Formula.installed.sort + elsif !args.command.nil? + path = Commands.path(args.command) + odie "Unknown command: #{args.command}" unless path + cmd_options = if cmd_parser = CLI::Parser.from_cmd_path(path) + cmd_parser.processed_options.map do |short, long, _, desc| + [long || short, desc] + end + else + cmd_comment_options(path) + end + if args.compact? + puts cmd_options.sort.map(&:first) * " " + else + cmd_options.sort.each { |option, desc| puts "#{option}\n\t#{desc}" } + puts + end elsif args.no_named? raise FormulaUnspecifiedError else @@ -39,6 +58,20 @@ module Homebrew end end + def cmd_comment_options(cmd_path) + options = [] + comment_lines = cmd_path.read.lines.grep(/^#:/) + return options if comment_lines.empty? + + # skip the comment's initial usage summary lines + comment_lines.slice(2..-1).each do |line| + if / (?<option>-[-\w]+) +(?<desc>.*)$/ =~ line + options << [option, desc] + end + end + options + end + def puts_options(formulae) formulae.each do |f| next if f.options.empty? diff --git a/docs/Manpage.md b/docs/Manpage.md index 5c3623264841ef7533f073379631c98e4a7cb7bb..b0d3faeebedbf024a139b7bd3fdb64253dd4e784 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -340,6 +340,8 @@ Show install options specific to *`formula`*. Show options for formulae that are currently installed. * `--all`: Show options for all available formulae. +* `--command`: + Show options for the specified *`command`*. ### `outdated` [*`options`*] [*`formula`*] diff --git a/manpages/brew.1 b/manpages/brew.1 index b3ed4b1578b8d0b22f04611bd73437cf1bc10e4e..3ba61bab212ba39e8ffebcbdba3f970d5fff7c36 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -456,6 +456,10 @@ Show options for formulae that are currently installed\. \fB\-\-all\fR Show options for all available formulae\. . +.TP +\fB\-\-command\fR +Show options for the specified \fIcommand\fR\. +. .SS "\fBoutdated\fR [\fIoptions\fR] [\fIformula\fR]" List installed formulae that have an updated version available\. By default, version information is displayed in interactive shells, and suppressed otherwise\. .