From 45950bb8ada58bc8b130bbc5a1678649a36342df Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 20 Nov 2020 00:35:48 +0100 Subject: [PATCH] Support casks in `brew edit`. --- Library/Homebrew/cli/named_args.rb | 2 +- Library/Homebrew/dev-cmd/edit.rb | 20 +++++++++++++++----- docs/Manpage.md | 11 ++++++++--- manpages/brew.1 | 12 ++++++++++-- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/cli/named_args.rb b/Library/Homebrew/cli/named_args.rb index f827bc070f..bed08e85e6 100644 --- a/Library/Homebrew/cli/named_args.rb +++ b/Library/Homebrew/cli/named_args.rb @@ -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 diff --git a/Library/Homebrew/dev-cmd/edit.rb b/Library/Homebrew/dev-cmd/edit.rb index 5526e9809e..dc4a814e5a 100644 --- a/Library/Homebrew/dev-cmd/edit.rb +++ b/Library/Homebrew/dev-cmd/edit.rb @@ -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` [] + `edit` [|] - Open in the editor set by `EDITOR` or `HOMEBREW_EDITOR`, or open the - Homebrew repository for editing if no formula is provided. + Open a or 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. " \ diff --git a/docs/Manpage.md b/docs/Manpage.md index 9f5b14a52a..09bb9fa3de 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -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`* diff --git a/manpages/brew.1 b/manpages/brew.1 index d0902e08cb..c8660ba8d1 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -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\.