Skip to content

Commit

Permalink
Add --describe arg to brew add
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-h-chamberlain committed Dec 25, 2023
1 parent 58cd1e2 commit 86cbda6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmd/add.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def add_args

switch "--formula", "--formulae", description: "Treat all named arguments as formulae."
switch "--cask", "--casks", description: "Treat all named arguments as casks."
switch "--describe",
env: :bundle_dump_describe,
description: "`add` adds a description comment above each line, unless the " \
"package does not have a description. " \
"This is enabled by default if HOMEBREW_BUNDLE_DUMP_DESCRIBE is set."

conflicts "formula", "cask"

Expand Down Expand Up @@ -98,7 +103,15 @@ def add

# Add the formula/cask to the file if it hasn't already been added.
unless current_bundle_list.include?(brew.full_name) || (brew_name_resolves_to_full_name && current_bundle_list.include?(brew_name))
file << "#{brewfile_prefix_type} #{quote_type}#{brew.full_name}#{quote_type}" << "\n"
# Adapted from `BrewDumper.dump`:
# https://github.com/Homebrew/homebrew-bundle/blob/master/lib/bundle/brew_dumper.rb#L59-L64
brewline = if args.describe? && brew.desc
brew.desc.split("\n").map { |s| "# #{s}\n" }.join
else
""
end

file << brewline + "#{brewfile_prefix_type} #{quote_type}#{brew.full_name}#{quote_type}" << "\n"

oh1 "Added #{display_type} #{Formatter.identifier(brew.full_name)} to Brewfile" unless silent

Expand Down

0 comments on commit 86cbda6

Please sign in to comment.