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

fetch: Use CLI::Parser to parse args #5201

Merged
merged 2 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
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
47 changes: 42 additions & 5 deletions Library/Homebrew/cmd/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,60 @@
#:
#: If `--deps` is passed, also download dependencies for any listed <formulae>.
#:
#: If `--build-from-source` (or `-s`) is passed, download the source rather than a
#: bottle.
#: If `--build-from-source` (or `-s`) or `--build-bottle` is passed, download the
#: source rather than a bottle.
#:
#: If `--force-bottle` is passed, download a bottle if it exists for the
#: current or newest version of macOS, even if it would not be used during
#: installation.

require "formula"
require "fetch"
require "cli_parser"

module Homebrew
module_function

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

Download the source packages for the given <formulae>.
For tarballs, also print SHA-256 checksums.
EOS
switch "--HEAD",
description: "Fetch HEAD version instead of stable version."
switch "--devel",
description: "Fetch devel version instead of stable version."
switch :verbose,
description: "Do a verbose VCS checkout, if the URL represents a VCS. This is useful for "\
"seeing if an existing VCS cache has been updated."
switch :force,
description: "Remove a previously cached version and re-fetch."
switch "--retry",
description: "Retry if a download fails or re-download if the checksum of a previously cached "\
"version no longer matches."
switch "--deps",
description: "Download dependencies for any listed <formulae>."
switch "-s", "--build-from-source",
description: "Download the source for rather than a bottle."
switch "--build-bottle",
description: "Download the source (for eventual bottling) rather than a bottle."
switch "--force-bottle",
description: "Download a bottle if it exists for the current or newest version of macOS, "\
"even if it would not be used during installation."
switch :verbose
switch :debug
end
end

def fetch
fetch_args.parse

raise FormulaUnspecifiedError if ARGV.named.empty?

if ARGV.include? "--deps"
if args.deps?
bucket = []
ARGV.formulae.each do |f|
bucket << f
Expand Down Expand Up @@ -100,7 +137,7 @@ def fetch_patch(p)

def retry_fetch?(f)
@fetch_failed ||= Set.new
if ARGV.include?("--retry") && @fetch_failed.add?(f)
if args.retry? && @fetch_failed.add?(f)
ohai "Retrying download"
f.clear_cache
true
Expand All @@ -111,7 +148,7 @@ def retry_fetch?(f)
end

def fetch_fetchable(f)
f.clear_cache if ARGV.force?
f.clear_cache if args.force?

already_fetched = f.cached_download.exist?

Expand Down
4 changes: 2 additions & 2 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ these flags should only appear after a command.

If `--deps` is passed, also download dependencies for any listed *`formulae`*.

If `--build-from-source` (or `-s`) is passed, download the source rather than a
bottle.
If `--build-from-source` (or `-s`) or `--build-bottle` is passed, download the
source rather than a bottle.

If `--force-bottle` is passed, download a bottle if it exists for the
current or newest version of macOS, even if it would not be used during
Expand Down
2 changes: 1 addition & 1 deletion manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ If \fB\-\-retry\fR is passed, retry if a download fails or re\-download if the c
If \fB\-\-deps\fR is passed, also download dependencies for any listed \fIformulae\fR\.
.
.IP
If \fB\-\-build\-from\-source\fR (or \fB\-s\fR) is passed, download the source rather than a bottle\.
If \fB\-\-build\-from\-source\fR (or \fB\-s\fR) or \fB\-\-build\-bottle\fR is passed, download the source rather than a bottle\.
.
.IP
If \fB\-\-force\-bottle\fR is passed, download a bottle if it exists for the current or newest version of macOS, even if it would not be used during installation\.
Expand Down