-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/deps: add args to filter output #17129
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -33,17 +33,30 @@ | |||||
description: "List dependencies by their full name." | ||||||
switch "--include-build", | ||||||
description: "Include `:build` dependencies for <formula>." | ||||||
switch "--direct-build", | ||||||
depends_on: "--include-build", | ||||||
description: "Only include `:build` dependencies that are direct dependencies declared " \ | ||||||
"in the formula." | ||||||
switch "--include-optional", | ||||||
description: "Include `:optional` dependencies for <formula>." | ||||||
switch "--include-test", | ||||||
description: "Include `:test` dependencies for <formula> (non-recursive)." | ||||||
description: "Include `:test` dependencies for <formula> (non-recursive for flat output)." | ||||||
switch "--direct-test", | ||||||
depends_on: "--include-test", | ||||||
description: "Only include `:test` dependencies that are direct dependencies declared " \ | ||||||
"in the formula when showing non-flat output like `--tree` or `--graph`." | ||||||
switch "--skip-recommended", | ||||||
description: "Skip `:recommended` dependencies for <formula>." | ||||||
comma_array "--skip", | ||||||
description: "Skip specified dependencies in the output." | ||||||
switch "--include-requirements", | ||||||
description: "Include requirements in addition to dependencies for <formula>." | ||||||
switch "--tree", | ||||||
description: "Show dependencies as a tree. When given multiple formula arguments, " \ | ||||||
"show individual trees for each formula." | ||||||
flag "--level=", | ||||||
depends_on: "--tree", | ||||||
description: "Limit depth of recursive dependencies in `--tree`." | ||||||
switch "--graph", | ||||||
description: "Show dependencies as a directed graph." | ||||||
switch "--dot", | ||||||
|
@@ -75,6 +88,7 @@ | |||||
switch "--cask", "--casks", | ||||||
description: "Treat all named arguments as casks." | ||||||
|
||||||
conflicts "--direct", "--level" | ||||||
conflicts "--tree", "--graph" | ||||||
conflicts "--installed", "--missing" | ||||||
conflicts "--installed", "--eval-all" | ||||||
|
@@ -88,6 +102,9 @@ | |||||
def run | ||||||
raise UsageError, "`brew deps --os=all` is not supported" if args.os == "all" | ||||||
raise UsageError, "`brew deps --arch=all` is not supported" if args.arch == "all" | ||||||
if (level = args.level) && !level.match?(/^[1-9][0-9]*$/) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
maybe with exception There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing some basic testing: it doesn't look like a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using irb(main):001:0> "skdfjsdklj100".to_i
=> 0
irb(main):002:0> "100alskdfsdkjfs".to_i
=> 100 |
||||||
raise UsageError, "`brew deps --level=<n>` needs a positive integer depth" | ||||||
end | ||||||
|
||||||
os, arch = T.must(args.os_arch_combinations.first) | ||||||
all = args.eval_all? | ||||||
|
@@ -107,6 +124,7 @@ | |||||
!args.include_optional? && | ||||||
!args.skip_recommended? && | ||||||
!args.missing? && | ||||||
args.skip.blank? && | ||||||
args.os.nil? && | ||||||
args.arch.nil? | ||||||
|
||||||
|
@@ -213,15 +231,15 @@ | |||||
end | ||||||
|
||||||
def deps_for_dependent(dependency, recursive: false) | ||||||
includes, ignores = args_includes_ignores(args) | ||||||
includes, ignores, recursive_ignores = args_includes_ignores(args) | ||||||
|
||||||
deps = dependency.runtime_dependencies if @use_runtime_dependencies | ||||||
|
||||||
if recursive | ||||||
deps ||= recursive_includes(Dependency, dependency, includes, ignores) | ||||||
deps ||= recursive_includes(Dependency, dependency, includes, ignores, recursive_ignores:, skip: args.skip) | ||||||
reqs = recursive_includes(Requirement, dependency, includes, ignores) | ||||||
else | ||||||
deps ||= select_includes(dependency.deps, ignores, includes) | ||||||
deps ||= select_includes(dependency.deps, ignores, includes, skip: args.skip) | ||||||
reqs = select_includes(dependency.requirements, ignores, includes) | ||||||
end | ||||||
|
||||||
|
@@ -272,10 +290,10 @@ | |||||
"digraph {\n#{dot_code}\n}" | ||||||
end | ||||||
|
||||||
def graph_deps(formula, dep_graph:, recursive:) | ||||||
def graph_deps(formula, dep_graph:, recursive:, recursing: false) | ||||||
return if dep_graph.key?(formula) | ||||||
|
||||||
dependables = dependables(formula) | ||||||
dependables = dependables(formula, recursing:) | ||||||
dep_graph[formula] = dependables | ||||||
return unless recursive | ||||||
|
||||||
|
@@ -284,7 +302,8 @@ | |||||
|
||||||
graph_deps(Formulary.factory(dep.name), | ||||||
dep_graph:, | ||||||
recursive: true) | ||||||
recursive: true, | ||||||
recursing: true) | ||||||
end | ||||||
end | ||||||
|
||||||
|
@@ -297,17 +316,18 @@ | |||||
end | ||||||
end | ||||||
|
||||||
def dependables(formula) | ||||||
includes, ignores = args_includes_ignores(args) | ||||||
def dependables(formula, recursing: false) | ||||||
includes, ignores, recursive_ignores = args_includes_ignores(args) | ||||||
includes -= recursive_ignores if recursing | ||||||
deps = @use_runtime_dependencies ? formula.runtime_dependencies : formula.deps | ||||||
deps = select_includes(deps, ignores, includes) | ||||||
deps = select_includes(deps, ignores, includes, skip: args.skip) | ||||||
reqs = select_includes(formula.requirements, ignores, includes) if args.include_requirements? | ||||||
reqs ||= [] | ||||||
reqs + deps | ||||||
end | ||||||
|
||||||
def recursive_deps_tree(formula, dep_stack:, prefix:, recursive:) | ||||||
dependables = dependables(formula) | ||||||
dependables = dependables(formula, recursing: dep_stack.length.positive?) | ||||||
max = dependables.length - 1 | ||||||
dep_stack.push formula.name | ||||||
dependables.each_with_index do |dep, i| | ||||||
|
@@ -329,6 +349,7 @@ | |||||
puts "#{prefix}#{display_s}" | ||||||
|
||||||
next if !recursive || is_circular | ||||||
next if dep_stack.length == args.level.to_i | ||||||
|
||||||
prefix_addition = if i == max | ||||||
" " | ||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we'd be better off just making the
--direct-test
behavior the default for the--include-test
option instead. It's always been a bit weird that the output is different depending on whether you're using the tree, graph or flat output.