81 lines
2.7 KiB
Ruby
Raw Normal View History

2020-11-25 17:03:23 +01:00
# typed: true
# frozen_string_literal: true
2019-04-17 18:25:08 +09:00
require "cli/parser"
2018-11-10 22:36:30 +05:30
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 "`tap` [<options>] [<user>`/`<repo>] [<URL>]"
description <<~EOS
2018-11-10 22:36:30 +05:30
Tap a formula repository.
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
using protocols other than HTTPS, e.g. SSH, git, HTTP, FTP(S), rsync.
2018-11-10 22:36:30 +05:30
EOS
switch "--full",
description: "Convert a shallow clone to a full clone without untapping. Taps are only cloned as "\
"shallow clones if `--shallow` was originally passed."
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
2021-01-10 14:26:40 -05:00
named_args :tap, max: 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?
Tap.each(&:link_completions_and_manpages)
Tap.each(&:fix_remote_configuration)
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)
elsif args.no_named?
puts Tap.names
2012-03-02 20:28:54 +00:00
else
odeprecated "`brew tap --full`" if args.full?
2021-05-07 09:55:56 -04:00
odeprecated "`brew tap --shallow`" if args.shallow?
tap = Tap.fetch(args.named.first)
2015-11-10 18:33:57 +08:00
begin
tap.install clone_target: args.named.second,
2020-07-31 19:29:11 +02:00
force_auto_update: force_auto_update?(args: args),
2021-05-06 09:56:30 -04:00
quiet: args.quiet?
rescue TapRemoteMismatchError => e
odie e
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:)
# 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?
end
2012-03-16 12:49:09 +00:00
end