Merge pull request #5846 from EricFromCanada/deps-option-fixes

deps: fix --1 and --annotate options
This commit is contained in:
Mike McQuaid 2019-03-08 13:14:31 +00:00 committed by GitHub
commit d8c6f6b120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 13 deletions

View File

@ -38,6 +38,9 @@ module Homebrew
switch "--tree", switch "--tree",
description: "Show dependencies as a tree. When given multiple formula arguments "\ description: "Show dependencies as a tree. When given multiple formula arguments "\
"output individual trees for every formula." "output individual trees for every formula."
switch "--annotate",
description: "Mark any build, test, optional, or recommended dependencies as "\
"such in the output."
switch "--for-each", switch "--for-each",
description: "Switch into the mode used by `deps --all`, but only list dependencies "\ description: "Switch into the mode used by `deps --all`, but only list dependencies "\
"for specified formula one specified formula per line. This is used for "\ "for specified formula one specified formula per line. This is used for "\
@ -58,26 +61,28 @@ module Homebrew
topo_order?: args.n?, topo_order?: args.n?,
union?: args.union?, union?: args.union?,
for_each?: args.for_each?, for_each?: args.for_each?,
recursive?: !args.send("1?"),
) )
if mode.tree? if mode.tree?
if mode.installed? if mode.installed?
puts_deps_tree Formula.installed.sort, !args.send("1?") puts_deps_tree Formula.installed.sort, mode.recursive?
else else
raise FormulaUnspecifiedError if args.remaining.empty? raise FormulaUnspecifiedError if args.remaining.empty?
puts_deps_tree ARGV.formulae, !args.send("1?") puts_deps_tree ARGV.formulae, mode.recursive?
end end
return return
elsif mode.all? elsif mode.all?
puts_deps Formula.sort puts_deps Formula.sort, mode.recursive?
return return
elsif !args.remaining.empty? && mode.for_each? elsif !args.remaining.empty? && mode.for_each?
puts_deps ARGV.formulae puts_deps ARGV.formulae, mode.recursive?
return return
end end
@only_installed_arg = args.installed? && @only_installed_arg = mode.installed? &&
mode.recursive? &&
!args.include_build? && !args.include_build? &&
!args.include_test? && !args.include_test? &&
!args.include_optional? && !args.include_optional? &&
@ -86,11 +91,11 @@ module Homebrew
if args.remaining.empty? if args.remaining.empty?
raise FormulaUnspecifiedError unless mode.installed? raise FormulaUnspecifiedError unless mode.installed?
puts_deps Formula.installed.sort puts_deps Formula.installed.sort, mode.recursive?
return return
end end
all_deps = deps_for_formulae(ARGV.formulae, !args.send("1?"), &(mode.union? ? :| : :&)) all_deps = deps_for_formulae(ARGV.formulae, mode.recursive?, &(mode.union? ? :| : :&))
all_deps = condense_requirements(all_deps) all_deps = condense_requirements(all_deps)
all_deps.select!(&:installed?) if mode.installed? all_deps.select!(&:installed?) if mode.installed?
all_deps.map!(&method(:dep_display_name)) all_deps.map!(&method(:dep_display_name))
@ -120,10 +125,11 @@ module Homebrew
end end
if args.annotate? if args.annotate?
str = "#{str} [build]" if dep.build? str = "#{str} " if args.tree?
str = "#{str} [test]" if dep.test? str = "#{str} [build]" if dep.build?
str = "#{str} [optional]" if dep.optional? str = "#{str} [test]" if dep.test?
str = "#{str} [recommended]" if dep.recommended? str = "#{str} [optional]" if dep.optional?
str = "#{str} [recommended]" if dep.recommended?
end end
str str
@ -149,9 +155,9 @@ module Homebrew
formulae.map { |f| deps_for_formula(f, recursive) }.reduce(&block) formulae.map { |f| deps_for_formula(f, recursive) }.reduce(&block)
end end
def puts_deps(formulae) def puts_deps(formulae, recursive = false)
formulae.each do |f| formulae.each do |f|
deps = deps_for_formula(f) deps = deps_for_formula(f, recursive)
deps = condense_requirements(deps) deps = condense_requirements(deps)
deps.sort_by!(&:name) deps.sort_by!(&:name)
deps.map!(&method(:dep_display_name)) deps.map!(&method(:dep_display_name))

View File

@ -112,6 +112,8 @@ show the intersection of dependencies for *`formula`*.
Include requirements in addition to dependencies for *`formula`*. Include requirements in addition to dependencies for *`formula`*.
* `--tree`: * `--tree`:
Show dependencies as a tree. When given multiple formula arguments output individual trees for every formula. Show dependencies as a tree. When given multiple formula arguments output individual trees for every formula.
* `--annotate`:
Mark any build, test, optional, or recommended dependencies as such in the output.
* `--for-each`: * `--for-each`:
Switch into the mode used by `deps --all`, but only list dependencies for specified formula one specified formula per line. This is used for debugging the `--installed`/`--all` display mode. Switch into the mode used by `deps --all`, but only list dependencies for specified formula one specified formula per line. This is used for debugging the `--installed`/`--all` display mode.

View File

@ -131,6 +131,10 @@ Include requirements in addition to dependencies for \fIformula\fR\.
Show dependencies as a tree\. When given multiple formula arguments output individual trees for every formula\. Show dependencies as a tree\. When given multiple formula arguments output individual trees for every formula\.
. .
.TP .TP
\fB\-\-annotate\fR
Mark any build, test, optional, or recommended dependencies as such in the output\.
.
.TP
\fB\-\-for\-each\fR \fB\-\-for\-each\fR
Switch into the mode used by \fBdeps \-\-all\fR, but only list dependencies for specified formula one specified formula per line\. This is used for debugging the \fB\-\-installed\fR/\fB\-\-all\fR display mode\. Switch into the mode used by \fBdeps \-\-all\fR, but only list dependencies for specified formula one specified formula per line\. This is used for debugging the \fB\-\-installed\fR/\fB\-\-all\fR display mode\.
. .