2020-11-25 17:03:23 +01:00
|
|
|
# typed: true
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2018-11-10 22:36:30 +05:30
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2020-10-20 12:03:48 +02:00
|
|
|
extend T::Sig
|
|
|
|
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2020-10-20 12:03:48 +02:00
|
|
|
sig { returns(CLI::Parser) }
|
2018-11-10 22:36:30 +05:30
|
|
|
def tap_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
2020-04-18 12:13:43 -04:00
|
|
|
`tap` [<options>] [<user>`/`<repo>] [<URL>]
|
2018-11-10 22:36:30 +05:30
|
|
|
|
|
|
|
Tap a formula repository.
|
|
|
|
|
2019-08-20 00:04:14 -04:00
|
|
|
If no arguments are provided, list all installed taps.
|
2018-11-10 22:36:30 +05:30
|
|
|
|
2019-08-06 14:22:24 -04:00
|
|
|
With <URL> unspecified, tap a formula repository from GitHub using HTTPS.
|
2018-11-10 22:36:30 +05:30
|
|
|
Since so many taps are hosted on GitHub, this command is a shortcut for
|
|
|
|
`brew tap` <user>`/`<repo> `https://github.com/`<user>`/homebrew-`<repo>.
|
|
|
|
|
2019-08-06 14:22:24 -04:00
|
|
|
With <URL> specified, tap a formula repository from anywhere, using
|
2019-08-06 14:20:27 -04:00
|
|
|
any transport protocol that `git`(1) handles. The one-argument form of `tap`
|
2018-11-10 22:36:30 +05:30
|
|
|
simplifies but also limits. This two-argument command makes no
|
|
|
|
assumptions, so taps can be cloned from places other than GitHub and
|
2020-02-19 10:56:44 +00:00
|
|
|
using protocols other than HTTPS, e.g. SSH, git, HTTP, FTP(S), rsync.
|
2018-11-10 22:36:30 +05:30
|
|
|
EOS
|
|
|
|
switch "--full",
|
2020-04-11 12:35:17 +10:00
|
|
|
description: "Convert a shallow clone to a full clone without untapping. Taps are only cloned as "\
|
2020-10-09 09:32:38 +01:00
|
|
|
"shallow clones if `--shallow` was originally passed."
|
2020-04-09 18:36:36 +10:00
|
|
|
switch "--shallow",
|
|
|
|
description: "Fetch tap as a shallow clone rather than a full clone. Useful for continuous integration."
|
2018-11-10 22:36:30 +05:30
|
|
|
switch "--force-auto-update",
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Auto-update tap even if it is not hosted on GitHub. By default, only taps "\
|
|
|
|
"hosted on GitHub are auto-updated (for performance reasons)."
|
2018-11-10 22:36:30 +05:30
|
|
|
switch "--repair",
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Migrate tapped formulae from symlink-based to directory-based structure."
|
2018-11-10 22:36:30 +05:30
|
|
|
switch "--list-pinned",
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "List all pinned taps."
|
2020-07-30 18:40:10 +02:00
|
|
|
|
2019-12-13 16:50:54 -05:00
|
|
|
max_named 2
|
2018-11-10 22:36:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-29 22:35:10 +01:00
|
|
|
sig { void }
|
2012-03-02 20:28:54 +00:00
|
|
|
def tap
|
2020-07-30 18:40:10 +02:00
|
|
|
args = tap_args.parse
|
2018-11-10 22:36:30 +05:30
|
|
|
|
|
|
|
if args.repair?
|
2016-09-30 18:22:53 -05:00
|
|
|
Tap.each(&:link_completions_and_manpages)
|
2018-11-10 22:36:30 +05:30
|
|
|
elsif args.list_pinned?
|
2015-08-21 12:33:33 +08:00
|
|
|
puts Tap.select(&:pinned?).map(&:name)
|
2020-03-04 17:28:15 +00:00
|
|
|
elsif args.no_named?
|
2015-12-26 13:01:52 +08:00
|
|
|
puts Tap.names
|
2012-03-02 20:28:54 +00:00
|
|
|
else
|
2020-04-11 12:35:17 +10:00
|
|
|
full_clone = if args.full?
|
|
|
|
true
|
|
|
|
else
|
|
|
|
!args.shallow?
|
|
|
|
end
|
|
|
|
odebug "Tapping as #{full_clone ? "full" : "shallow"} clone"
|
2020-03-04 17:28:15 +00:00
|
|
|
tap = Tap.fetch(args.named.first)
|
2015-11-10 18:33:57 +08:00
|
|
|
begin
|
2020-03-04 17:28:15 +00:00
|
|
|
tap.install clone_target: args.named.second,
|
2020-07-31 19:29:11 +02:00
|
|
|
force_auto_update: force_auto_update?(args: args),
|
2020-04-09 18:36:36 +10:00
|
|
|
quiet: args.quiet?,
|
2020-04-11 12:35:17 +10:00
|
|
|
full_clone: full_clone
|
2016-04-04 03:18:55 -07:00
|
|
|
rescue TapRemoteMismatchError => e
|
|
|
|
odie e
|
2020-02-02 16:36:01 +01:00
|
|
|
rescue TapAlreadyTappedError
|
|
|
|
nil
|
2015-11-10 09:12:25 +00:00
|
|
|
end
|
2012-03-02 20:28:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-31 19:29:11 +02:00
|
|
|
def force_auto_update?(args:)
|
2018-04-12 16:14:02 -07:00
|
|
|
# if no relevant flag is present, return nil, meaning "no change"
|
2018-11-10 22:36:30 +05:30
|
|
|
true if args.force_auto_update?
|
2018-04-12 16:14:02 -07:00
|
|
|
end
|
2012-03-16 12:49:09 +00:00
|
|
|
end
|