Skip to content
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

uses: Use CLI::Parser to parse args #5305

Merged
merged 1 commit into from
Nov 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 45 additions & 8 deletions Library/Homebrew/cmd/uses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#: `--devel` or `--HEAD`.

require "formula"
require "cli_parser"

# `brew uses foo bar` returns formulae that use both foo and bar
# If you want the union, run the command twice and concatenate the results.
Expand All @@ -27,8 +28,44 @@
module Homebrew
module_function

def uses_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`uses` [<options>] <formulae>

Show the formulae that specify <formulae> as a dependency. When given
multiple formula arguments, show the intersection of formulae that use
<formulae>.

By default, `uses` shows all formulae that specify <formulae> as a required
or recommended dependency.

By default, `uses` shows usage of <formulae> by stable builds.
EOS
switch "--recursive",
description: "Resolve more than one level of dependencies."
switch "--installed",
description: "Only list installed formulae."
switch "--include-build",
description: "Include all formulae that specify <formulae> as `:build` type dependency."
switch "--include-test",
description: "Include all formulae that specify <formulae> as `:test` type dependency."
switch "--include-optional",
description: "Include all formulae that specify <formulae> as `:optional` type dependency."
switch "--skip-recommended",
description: "Skip all formulae that specify <formulae> as `:recommended` type dependency."
switch "--devel",
description: "Show usage of <formulae> by development build."
switch "--HEAD",
description: "Show usage of <formulae> by HEAD build."
switch :debug
end
end

def uses
raise FormulaUnspecifiedError if ARGV.named.empty?
uses_args.parse

raise FormulaUnspecifiedError if args.remaining.empty?

used_formulae_missing = false
used_formulae = begin
Expand All @@ -40,13 +77,13 @@ def uses
ARGV.named.map { |name| OpenStruct.new name: name, full_name: name }
end

formulae = ARGV.include?("--installed") ? Formula.installed : Formula
recursive = ARGV.flag? "--recursive"
only_installed_arg = ARGV.include?("--installed") &&
!ARGV.include?("--include-build") &&
!ARGV.include?("--include-test") &&
!ARGV.include?("--include-optional") &&
!ARGV.include?("--skip-recommended")
formulae = args.installed? ? Formula.installed : Formula
recursive = args.recursive?
only_installed_arg = args.installed? &&
!args.include_build? &&
!args.include_test? &&
!args.include_optional? &&
!args.skip_recommended?

includes, ignores = argv_includes_ignores(ARGV)

Expand Down