From a6a3ed1ceee6a74a089c7a40e692c58c73c42489 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sat, 27 Oct 2018 23:44:32 +0530 Subject: [PATCH 1/2] fetch: Use CLI::Parser to parse args --- Library/Homebrew/cmd/fetch.rb | 41 ++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index 892c6426d3093..b165a97ff8a3b 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -24,14 +24,49 @@ require "formula" require "fetch" +require "cli_parser" module Homebrew module_function + def fetch_args + Homebrew::CLI::Parser.new do + usage_banner <<~EOS + `fetch` [] + + Download the source packages for the given . + 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 ." + switch "-s", "--build-from-source", + description: "Download the source 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 @@ -100,7 +135,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 @@ -111,7 +146,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? From fe8f3218d30e4b3813364683d21f52ad77057af3 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 29 Jan 2019 11:35:04 +0000 Subject: [PATCH 2/2] cmd/fetch: add missing `--build-bottle` argument. --- Library/Homebrew/cmd/fetch.rb | 8 +++++--- docs/Manpage.md | 4 ++-- manpages/brew.1 | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index b165a97ff8a3b..3b870b364038b 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -15,8 +15,8 @@ #: #: If `--deps` is passed, also download dependencies for any listed . #: -#: 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 @@ -52,7 +52,9 @@ def fetch_args switch "--deps", description: "Download dependencies for any listed ." switch "-s", "--build-from-source", - description: "Download the source rather than a bottle." + 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." diff --git a/docs/Manpage.md b/docs/Manpage.md index 2c7117f1a750a..347651074a647 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -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 diff --git a/manpages/brew.1 b/manpages/brew.1 index 4aa57bc90ceaf..43d412423e7e9 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -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\.