Merge pull request #9035 from MikeMcQuaid/ls-flags

list: fix flag handling.
This commit is contained in:
Mike McQuaid 2020-11-03 15:00:25 +00:00 committed by GitHub
commit dbdf7cf265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 37 deletions

View File

@ -506,7 +506,7 @@ module Homebrew
end end
end end
class OptionConstraintError < RuntimeError class OptionConstraintError < UsageError
def initialize(arg1, arg2, missing: false) def initialize(arg1, arg2, missing: false)
message = if !missing message = if !missing
"`#{arg1}` and `#{arg2}` should be passed together." "`#{arg1}` and `#{arg2}` should be passed together."
@ -517,7 +517,7 @@ module Homebrew
end end
end end
class OptionConflictError < RuntimeError class OptionConflictError < UsageError
def initialize(args) def initialize(args)
args_list = args.map(&Formatter.public_method(:option)) args_list = args.map(&Formatter.public_method(:option))
.join(" and ") .join(" and ")
@ -525,7 +525,7 @@ module Homebrew
end end
end end
class InvalidConstraintError < RuntimeError class InvalidConstraintError < UsageError
def initialize(arg1, arg2) def initialize(arg1, arg2)
super "`#{arg1}` and `#{arg2}` cannot be mutually exclusive and mutually dependent simultaneously." super "`#{arg1}` and `#{arg2}` cannot be mutually exclusive and mutually dependent simultaneously."
end end

View File

@ -18,38 +18,51 @@ module Homebrew
If <formula> is provided, summarise the paths within its current keg. If <formula> is provided, summarise the paths within its current keg.
EOS EOS
switch "--formula", "--formulae",
description: "List only formulae. `This is the default action on non TTY.`"
switch "--cask", "--casks",
description: "List only casks, or <cask> if provided."
switch "--unbrewed",
description: "List files in Homebrew's prefix not installed by Homebrew."
switch "--full-name", switch "--full-name",
depends_on: "--formula",
description: "Print formulae with fully-qualified names. If `--full-name` is not "\ description: "Print formulae with fully-qualified names. If `--full-name` is not "\
"passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are passed to `ls`(1) "\ "passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are passed to `ls`(1) "\
"which produces the actual output." "which produces the actual output."
switch "--unbrewed",
description: "List files in Homebrew's prefix not installed by Homebrew."
switch "--versions", switch "--versions",
depends_on: "--formula",
description: "Show the version number for installed formulae, or only the specified "\ description: "Show the version number for installed formulae, or only the specified "\
"formulae if <formula> are provided." "formulae if <formula> are provided."
switch "--multiple", switch "--multiple",
depends_on: "--versions", depends_on: "--versions",
description: "Only show formulae with multiple versions installed." description: "Only show formulae with multiple versions installed."
switch "--pinned", switch "--pinned",
depends_on: "--formula",
description: "Show the versions of pinned formulae, or only the specified (pinned) "\ description: "Show the versions of pinned formulae, or only the specified (pinned) "\
"formulae if <formula> are provided. See also `pin`, `unpin`." "formulae if <formula> are provided. See also `pin`, `unpin`."
switch "--formula", "--formulae",
description: "List only formulae. `This is the default action on non TTY.`"
switch "--cask", "--casks",
description: "List only casks, or <cask> if provided."
# passed through to ls # passed through to ls
switch "-1", switch "-1",
description: "Force output to be one entry per line. " \ description: "Force output to be one entry per line. " \
"This is the default when output is not to a terminal." "This is the default when output is not to a terminal."
switch "-l", switch "-l",
description: "List in long format. If the output is to a terminal, "\ depends_on: "--formula",
description: "List formulae in long format. If the output is to a terminal, "\
"a total sum for all the file sizes is printed before the long listing." "a total sum for all the file sizes is printed before the long listing."
switch "-r", switch "-r",
description: "Reverse the order of the sort to list the oldest entries first." depends_on: "--formula",
description: "Reverse the order of the formulae sort to list the oldest entries first."
switch "-t", switch "-t",
description: "Sort by time modified, listing most recently modified first." depends_on: "--formula",
description: "Sort formulae by time modified, listing most recently modified first."
["--formula", "--unbrewed", "--multiple", "--pinned", "-l", "-r", "-t"].each do |flag| ["-1", "-l", "-r", "-t"].each do |flag|
conflicts "--full-name", flag
conflicts "--unbrewed", flag
conflicts "--pinned", flag
conflicts "--versions", flag
end
["--unbrewed", "--formula", "-l", "-r", "-t"].each do |flag|
conflicts "--cask", flag conflicts "--cask", flag
end end
end end
@ -104,6 +117,7 @@ module Homebrew
UNBREWED_EXCLUDE_FILES = %w[.DS_Store].freeze UNBREWED_EXCLUDE_FILES = %w[.DS_Store].freeze
UNBREWED_EXCLUDE_PATHS = %w[ UNBREWED_EXCLUDE_PATHS = %w[
*/.keepme
.github/* .github/*
bin/brew bin/brew
completions/zsh/_brew completions/zsh/_brew
@ -126,7 +140,7 @@ module Homebrew
def list_unbrewed def list_unbrewed
dirs = HOMEBREW_PREFIX.subdirs.map { |dir| dir.basename.to_s } dirs = HOMEBREW_PREFIX.subdirs.map { |dir| dir.basename.to_s }
dirs -= %w[Library Cellar .git] dirs -= %w[Library Cellar Caskroom .git]
# Exclude cache, logs, and repository, if they are located under the prefix. # Exclude cache, logs, and repository, if they are located under the prefix.
[HOMEBREW_CACHE, HOMEBREW_LOGS, HOMEBREW_REPOSITORY].each do |dir| [HOMEBREW_CACHE, HOMEBREW_LOGS, HOMEBREW_REPOSITORY].each do |dir|

View File

@ -353,28 +353,28 @@ List all installed formulae or casks
If *`formula`* is provided, summarise the paths within its current keg. If *`formula`* is provided, summarise the paths within its current keg.
* `--full-name`: * `--formula`:
Print formulae with fully-qualified names. If `--full-name` is not passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are passed to `ls`(1) which produces the actual output. List only formulae. `This is the default action on non TTY.`
* `--cask`:
List only casks, or *`cask`* if provided.
* `--unbrewed`: * `--unbrewed`:
List files in Homebrew's prefix not installed by Homebrew. List files in Homebrew's prefix not installed by Homebrew.
* `--full-name`:
Print formulae with fully-qualified names. If `--full-name` is not passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are passed to `ls`(1) which produces the actual output.
* `--versions`: * `--versions`:
Show the version number for installed formulae, or only the specified formulae if *`formula`* are provided. Show the version number for installed formulae, or only the specified formulae if *`formula`* are provided.
* `--multiple`: * `--multiple`:
Only show formulae with multiple versions installed. Only show formulae with multiple versions installed.
* `--pinned`: * `--pinned`:
Show the versions of pinned formulae, or only the specified (pinned) formulae if *`formula`* are provided. See also `pin`, `unpin`. Show the versions of pinned formulae, or only the specified (pinned) formulae if *`formula`* are provided. See also `pin`, `unpin`.
* `--formula`:
List only formulae. `This is the default action on non TTY.`
* `--cask`:
List only casks, or *`cask`* if provided.
* `-1`: * `-1`:
Force output to be one entry per line. This is the default when output is not to a terminal. Force output to be one entry per line. This is the default when output is not to a terminal.
* `-l`: * `-l`:
List in long format. If the output is to a terminal, a total sum for all the file sizes is printed before the long listing. List formulae in long format. If the output is to a terminal, a total sum for all the file sizes is printed before the long listing.
* `-r`: * `-r`:
Reverse the order of the sort to list the oldest entries first. Reverse the order of the formulae sort to list the oldest entries first.
* `-t`: * `-t`:
Sort by time modified, listing most recently modified first. Sort formulae by time modified, listing most recently modified first.
### `log` [*`options`*] [*`formula`*] ### `log` [*`options`*] [*`formula`*]

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "BREW" "1" "October 2020" "Homebrew" "brew" .TH "BREW" "1" "November 2020" "Homebrew" "brew"
. .
.SH "NAME" .SH "NAME"
\fBbrew\fR \- The Missing Package Manager for macOS \fBbrew\fR \- The Missing Package Manager for macOS
@ -512,14 +512,22 @@ List all installed formulae or casks
If \fIformula\fR is provided, summarise the paths within its current keg\. If \fIformula\fR is provided, summarise the paths within its current keg\.
. .
.TP .TP
\fB\-\-full\-name\fR \fB\-\-formula\fR
Print formulae with fully\-qualified names\. If \fB\-\-full\-name\fR is not passed, other options (i\.e\. \fB\-1\fR, \fB\-l\fR, \fB\-r\fR and \fB\-t\fR) are passed to \fBls\fR(1) which produces the actual output\. List only formulae\. \fBThis is the default action on non TTY\.\fR
.
.TP
\fB\-\-cask\fR
List only casks, or \fIcask\fR if provided\.
. .
.TP .TP
\fB\-\-unbrewed\fR \fB\-\-unbrewed\fR
List files in Homebrew\'s prefix not installed by Homebrew\. List files in Homebrew\'s prefix not installed by Homebrew\.
. .
.TP .TP
\fB\-\-full\-name\fR
Print formulae with fully\-qualified names\. If \fB\-\-full\-name\fR is not passed, other options (i\.e\. \fB\-1\fR, \fB\-l\fR, \fB\-r\fR and \fB\-t\fR) are passed to \fBls\fR(1) which produces the actual output\.
.
.TP
\fB\-\-versions\fR \fB\-\-versions\fR
Show the version number for installed formulae, or only the specified formulae if \fIformula\fR are provided\. Show the version number for installed formulae, or only the specified formulae if \fIformula\fR are provided\.
. .
@ -532,28 +540,20 @@ Only show formulae with multiple versions installed\.
Show the versions of pinned formulae, or only the specified (pinned) formulae if \fIformula\fR are provided\. See also \fBpin\fR, \fBunpin\fR\. Show the versions of pinned formulae, or only the specified (pinned) formulae if \fIformula\fR are provided\. See also \fBpin\fR, \fBunpin\fR\.
. .
.TP .TP
\fB\-\-formula\fR
List only formulae\. \fBThis is the default action on non TTY\.\fR
.
.TP
\fB\-\-cask\fR
List only casks, or \fIcask\fR if provided\.
.
.TP
\fB\-1\fR \fB\-1\fR
Force output to be one entry per line\. This is the default when output is not to a terminal\. Force output to be one entry per line\. This is the default when output is not to a terminal\.
. .
.TP .TP
\fB\-l\fR \fB\-l\fR
List in long format\. If the output is to a terminal, a total sum for all the file sizes is printed before the long listing\. List formulae in long format\. If the output is to a terminal, a total sum for all the file sizes is printed before the long listing\.
. .
.TP .TP
\fB\-r\fR \fB\-r\fR
Reverse the order of the sort to list the oldest entries first\. Reverse the order of the formulae sort to list the oldest entries first\.
. .
.TP .TP
\fB\-t\fR \fB\-t\fR
Sort by time modified, listing most recently modified first\. Sort formulae by time modified, listing most recently modified first\.
. .
.SS "\fBlog\fR [\fIoptions\fR] [\fIformula\fR]" .SS "\fBlog\fR [\fIoptions\fR] [\fIformula\fR]"
Show the \fBgit log\fR for \fIformula\fR, or show the log for the Homebrew repository if no formula is provided\. Show the \fBgit log\fR for \fIformula\fR, or show the log for the Homebrew repository if no formula is provided\.