Support casks in brew edit.

This commit is contained in:
Markus Reiter 2020-11-20 00:35:48 +01:00
parent 6d850a97a1
commit 45950bb8ad
4 changed files with 34 additions and 11 deletions

View File

@ -142,7 +142,7 @@ module Homebrew
paths << formula_path if formula_path.exist?
paths << cask_path if cask_path.exist?
paths.empty? ? name : paths
paths.empty? ? Pathname(name) : paths
end
end.uniq.freeze
end

View File

@ -1,4 +1,4 @@
# typed: false
# typed: true
# frozen_string_literal: true
require "formula"
@ -13,17 +13,27 @@ module Homebrew
def edit_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`edit` [<formula>]
`edit` [<formula>|<cask>]
Open <formula> in the editor set by `EDITOR` or `HOMEBREW_EDITOR`, or open the
Homebrew repository for editing if no formula is provided.
Open a <formula> or <cask> in the editor set by `EDITOR` or `HOMEBREW_EDITOR`,
or open the Homebrew repository for editing if no formula is provided.
EOS
switch "--formula", "--formulae",
description: "Treat all named arguments as formulae."
switch "--cask", "--casks",
description: "Treat all named arguments as casks."
conflicts "--formula", "--cask"
end
end
sig { void }
def edit
args = edit_args.parse
only = :formula if args.formula? && !args.cask?
only = :cask if args.cask? && !args.formula?
unless (HOMEBREW_REPOSITORY/".git").directory?
raise <<~EOS
Changes will be lost!
@ -32,7 +42,7 @@ module Homebrew
EOS
end
paths = args.named.to_formulae_paths.select do |path|
paths = args.named.to_paths(only: only).select do |path|
next path if path.exist?
raise UsageError, "#{path} doesn't exist on disk. " \

View File

@ -997,10 +997,15 @@ the Cellar and then link it into Homebrew's prefix with `brew link`.
* `--version`:
Explicitly set the *`version`* of the package being installed.
### `edit` [*`formula`*]
### `edit` [*`formula`*|*`cask`*]
Open *`formula`* in the editor set by `EDITOR` or `HOMEBREW_EDITOR`, or open the
Homebrew repository for editing if no formula is provided.
Open a *`formula`* or *`cask`* in the editor set by `EDITOR` or `HOMEBREW_EDITOR`,
or open the Homebrew repository for editing if no formula is provided.
* `--formula`:
Treat all named arguments as formulae.
* `--cask`:
Treat all named arguments as casks.
### `extract` [*`options`*] *`formula`* *`tap`*

View File

@ -1393,8 +1393,16 @@ Explicitly set the \fIname\fR of the package being installed\.
\fB\-\-version\fR
Explicitly set the \fIversion\fR of the package being installed\.
.
.SS "\fBedit\fR [\fIformula\fR]"
Open \fIformula\fR in the editor set by \fBEDITOR\fR or \fBHOMEBREW_EDITOR\fR, or open the Homebrew repository for editing if no formula is provided\.
.SS "\fBedit\fR [\fIformula\fR|\fIcask\fR]"
Open a \fIformula\fR or \fIcask\fR in the editor set by \fBEDITOR\fR or \fBHOMEBREW_EDITOR\fR, or open the Homebrew repository for editing if no formula is provided\.
.
.TP
\fB\-\-formula\fR
Treat all named arguments as formulae\.
.
.TP
\fB\-\-cask\fR
Treat all named arguments as casks\.
.
.SS "\fBextract\fR [\fIoptions\fR] \fIformula\fR \fItap\fR"
Look through repository history to find the most recent version of \fIformula\fR and create a copy in \fItap\fR\fB/Formula/\fR\fIformula\fR\fB@\fR\fIversion\fR\fB\.rb\fR\. If the tap is not installed yet, attempt to install/clone the tap before continuing\. To extract a formula from a tap that is not \fBhomebrew/core\fR use its fully\-qualified form of \fIuser\fR\fB/\fR\fIrepo\fR\fB/\fR\fIformula\fR\.