forked from Homebrew/homebrew-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundle.rb
executable file
·198 lines (171 loc) · 8.29 KB
/
bundle.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# frozen_string_literal: true
homebrew_version = if HOMEBREW_VERSION.present?
HOMEBREW_VERSION.delete_prefix(">=")
.delete_suffix(" (shallow or no git repository)")
else
"0.0.1"
end
if Version.new(homebrew_version) < Version.new("4.2.15")
odie "Your Homebrew is too outdated for `brew bundle`. Please run `brew update`!"
end
require "abstract_command"
module Homebrew
module Cmd
class BundleCmd < AbstractCommand
cmd_args do
usage_banner <<~EOS
`bundle` [<subcommand>]
Bundler for non-Ruby dependencies from Homebrew, Homebrew Cask, Mac App Store, Whalebrew and Visual Studio Code.
`brew bundle` [`install`]:
Install and upgrade (by default) all dependencies from the `Brewfile`.
You can specify the `Brewfile` location using `--file` or by setting the `HOMEBREW_BUNDLE_FILE` environment variable.
You can skip the installation of dependencies by adding space-separated values to one or more of the following environment variables: `HOMEBREW_BUNDLE_BREW_SKIP`, `HOMEBREW_BUNDLE_CASK_SKIP`, `HOMEBREW_BUNDLE_MAS_SKIP`, `HOMEBREW_BUNDLE_WHALEBREW_SKIP`, `HOMEBREW_BUNDLE_TAP_SKIP`.
`brew bundle dump`:
Write all installed casks/formulae/images/taps into a `Brewfile` in the current directory.
`brew bundle cleanup`:
Uninstall all dependencies not present in the `Brewfile`.
This workflow is useful for maintainers or testers who regularly install lots of formulae.
Unless `--force` is passed, this returns a 1 exit code if anything would be removed.
`brew bundle check`:
Check if all dependencies present in the `Brewfile` are installed.
This provides a successful exit code if everything is up-to-date, making it useful for scripting.
`brew bundle list`:
List all dependencies present in the `Brewfile`.
By default, only Homebrew formula dependencies are listed.
`brew bundle exec` <command>:
Run an external command in an isolated build environment based on the `Brewfile` dependencies.
This sanitized build environment ignores unrequested dependencies, which makes sure that things you didn't specify in your `Brewfile` won't get picked up by commands like `bundle install`, `npm install`, etc. It will also add compiler flags which will help with finding keg-only dependencies like `openssl`, `icu4c`, etc.
EOS
flag "--file=",
description: "Read the `Brewfile` from this location. Use `--file=-` to pipe to stdin/stdout."
switch "--global",
description: "Read the `Brewfile` from `~/.Brewfile`, " \
"in the `HOMEBREW_USER_CONFIG_HOME` directory, " \
"or the `HOMEBREW_BUNDLE_FILE_GLOBAL` environment variable, if set."
switch "-v", "--verbose",
description: "`install` prints output from commands as they are run. " \
"`check` lists all missing dependencies."
switch "--no-upgrade",
description: "`install` does not run `brew upgrade` on outdated dependencies. " \
"Note they may still be upgraded by `brew install` if needed."
switch "-f", "--force",
description: "`install` runs with `--force`/`--overwrite`. " \
"`dump` overwrites an existing `Brewfile`. " \
"`cleanup` actually performs its cleanup operations."
switch "--cleanup",
env: :bundle_install_cleanup,
description: "`install` performs cleanup operation, same as running `cleanup --force`. " \
"This is enabled by default if `HOMEBREW_BUNDLE_INSTALL_CLEANUP` is set and " \
"`--global` is passed."
switch "--no-lock",
description: "no-op since `Brewfile.lock.json` was removed.",
hidden: true
switch "--all",
description: "`list` all dependencies."
switch "--formula", "--brews",
description: "`list` or `dump` Homebrew formula dependencies."
switch "--cask", "--casks",
description: "`list` or `dump` Homebrew cask dependencies."
switch "--tap", "--taps",
description: "`list` or `dump` Homebrew tap dependencies."
switch "--mas",
description: "`list` or `dump` Mac App Store dependencies."
switch "--whalebrew",
description: "`list` or `dump` Whalebrew dependencies."
switch "--vscode",
description: "`list` or `dump` VSCode extensions."
switch "--no-vscode",
env: :bundle_dump_no_vscode,
description: "`dump` without VSCode extensions. " \
"This is enabled by default if `HOMEBREW_BUNDLE_DUMP_NO_VSCODE` is set."
switch "--describe",
env: :bundle_dump_describe,
description: "`dump` adds a description comment above each line, unless the " \
"dependency does not have a description. " \
"This is enabled by default if `HOMEBREW_BUNDLE_DUMP_DESCRIBE` is set."
switch "--no-restart",
description: "`dump` does not add `restart_service` to formula lines."
switch "--zap",
description: "`cleanup` casks using the `zap` command instead of `uninstall`."
conflicts "--all", "--no-vscode"
conflicts "--vscode", "--no-vscode"
named_args %w[install dump cleanup check exec list]
end
def run
# Keep this inside `run` to keep --help fast.
require_relative "../lib/bundle"
subcommand = args.named.first.presence
if subcommand != "exec" && args.named.size > 1
raise UsageError, "This command does not take more than 1 subcommand argument."
end
global = args.global?
file = args.file
args.zap?
no_upgrade = args.no_upgrade?
verbose = args.verbose?
force = args.force?
zap = args.zap?
no_type_args = !args.brews? && !args.casks? && !args.taps? && !args.mas? && !args.whalebrew? && !args.vscode?
case subcommand
when nil, "install"
Bundle::Commands::Install.run(
global:, file:, no_upgrade:, verbose:, force:,
no_lock: args.no_lock?,
quiet: args.quiet?
)
cleanup = if ENV.fetch("HOMEBREW_BUNDLE_INSTALL_CLEANUP", nil)
args.global?
else
args.cleanup?
end
if cleanup
Bundle::Commands::Cleanup.run(
global:, file:, zap:,
force: true,
dsl: Bundle::Commands::Install.dsl
)
end
when "dump"
vscode = if args.no_vscode?
false
elsif args.vscode?
true
else
no_type_args
end
Bundle::Commands::Dump.run(
global:, file:, force:,
describe: args.describe?,
no_restart: args.no_restart?,
taps: args.taps? || no_type_args,
brews: args.brews? || no_type_args,
casks: args.casks? || no_type_args,
mas: args.mas? || no_type_args,
whalebrew: args.whalebrew? || no_type_args,
vscode:
)
when "cleanup"
Bundle::Commands::Cleanup.run(global:, file:, force:, zap:)
when "check"
Bundle::Commands::Check.run(global:, file:, no_upgrade:, verbose:)
when "exec"
_subcommand, *named_args = args.named
Bundle::Commands::Exec.run(*named_args, global:, file:)
when "list"
Bundle::Commands::List.run(
global:,
file:,
brews: args.brews? || args.all? || no_type_args,
casks: args.casks? || args.all?,
taps: args.taps? || args.all?,
mas: args.mas? || args.all?,
whalebrew: args.whalebrew? || args.all?,
vscode: args.vscode? || args.all?,
)
else
raise UsageError, "unknown subcommand: #{subcommand}"
end
end
end
end
end