Skip to content

Commit 5adb76a

Browse files
committed
list: fix flag handling.
Fix `-1` and other flags so they're handled correctly with casks. Use the "right" exceptions for declaring invalid combinations and change their parent class so that `--help` is printed nicely too. Fixes #9033
1 parent 9115ef7 commit 5adb76a

File tree

4 files changed

+51
-37
lines changed

4 files changed

+51
-37
lines changed

Library/Homebrew/cli/parser.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def formulae(argv)
506506
end
507507
end
508508

509-
class OptionConstraintError < RuntimeError
509+
class OptionConstraintError < UsageError
510510
def initialize(arg1, arg2, missing: false)
511511
message = if !missing
512512
"`#{arg1}` and `#{arg2}` should be passed together."
@@ -517,15 +517,15 @@ def initialize(arg1, arg2, missing: false)
517517
end
518518
end
519519

520-
class OptionConflictError < RuntimeError
520+
class OptionConflictError < UsageError
521521
def initialize(args)
522522
args_list = args.map(&Formatter.public_method(:option))
523523
.join(" and ")
524524
super "Options #{args_list} are mutually exclusive."
525525
end
526526
end
527527

528-
class InvalidConstraintError < RuntimeError
528+
class InvalidConstraintError < UsageError
529529
def initialize(arg1, arg2)
530530
super "`#{arg1}` and `#{arg2}` cannot be mutually exclusive and mutually dependent simultaneously."
531531
end

Library/Homebrew/cmd/list.rb

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,51 @@ def list_args
1818
1919
If <formula> is provided, summarise the paths within its current keg.
2020
EOS
21+
switch "--formula", "--formulae",
22+
description: "List only formulae. `This is the default action on non TTY.`"
23+
switch "--cask", "--casks",
24+
description: "List only casks, or <cask> if provided."
25+
switch "--unbrewed",
26+
description: "List files in Homebrew's prefix not installed by Homebrew."
2127
switch "--full-name",
28+
depends_on: "--formula",
2229
description: "Print formulae with fully-qualified names. If `--full-name` is not "\
2330
"passed, other options (i.e. `-1`, `-l`, `-r` and `-t`) are passed to `ls`(1) "\
2431
"which produces the actual output."
25-
switch "--unbrewed",
26-
description: "List files in Homebrew's prefix not installed by Homebrew."
2732
switch "--versions",
33+
depends_on: "--formula",
2834
description: "Show the version number for installed formulae, or only the specified "\
2935
"formulae if <formula> are provided."
3036
switch "--multiple",
3137
depends_on: "--versions",
3238
description: "Only show formulae with multiple versions installed."
3339
switch "--pinned",
40+
depends_on: "--formula",
3441
description: "Show the versions of pinned formulae, or only the specified (pinned) "\
3542
"formulae if <formula> are provided. See also `pin`, `unpin`."
36-
switch "--formula", "--formulae",
37-
description: "List only formulae. `This is the default action on non TTY.`"
38-
switch "--cask", "--casks",
39-
description: "List only casks, or <cask> if provided."
4043
# passed through to ls
4144
switch "-1",
4245
description: "Force output to be one entry per line. " \
4346
"This is the default when output is not to a terminal."
4447
switch "-l",
45-
description: "List in long format. If the output is to a terminal, "\
48+
depends_on: "--formula",
49+
description: "List formulae in long format. If the output is to a terminal, "\
4650
"a total sum for all the file sizes is printed before the long listing."
4751
switch "-r",
48-
description: "Reverse the order of the sort to list the oldest entries first."
52+
depends_on: "--formula",
53+
description: "Reverse the order of the formulae sort to list the oldest entries first."
4954
switch "-t",
50-
description: "Sort by time modified, listing most recently modified first."
55+
depends_on: "--formula",
56+
description: "Sort formulae by time modified, listing most recently modified first."
57+
58+
["-1", "-l", "-r", "-t"].each do |flag|
59+
conflicts "--full-name", flag
60+
conflicts "--unbrewed", flag
61+
conflicts "--pinned", flag
62+
conflicts "--versions", flag
63+
end
5164

52-
["--formula", "--unbrewed", "--multiple", "--pinned", "-l", "-r", "-t"].each do |flag|
65+
["--unbrewed", "--formula", "-l", "-r", "-t"].each do |flag|
5366
conflicts "--cask", flag
5467
end
5568
end
@@ -104,6 +117,7 @@ def list
104117

105118
UNBREWED_EXCLUDE_FILES = %w[.DS_Store].freeze
106119
UNBREWED_EXCLUDE_PATHS = %w[
120+
*/.keepme
107121
.github/*
108122
bin/brew
109123
completions/zsh/_brew
@@ -126,7 +140,7 @@ def list
126140

127141
def list_unbrewed
128142
dirs = HOMEBREW_PREFIX.subdirs.map { |dir| dir.basename.to_s }
129-
dirs -= %w[Library Cellar .git]
143+
dirs -= %w[Library Cellar Caskroom .git]
130144

131145
# Exclude cache, logs, and repository, if they are located under the prefix.
132146
[HOMEBREW_CACHE, HOMEBREW_LOGS, HOMEBREW_REPOSITORY].each do |dir|

docs/Manpage.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,28 +353,28 @@ List all installed formulae or casks
353353

354354
If *`formula`* is provided, summarise the paths within its current keg.
355355

356-
* `--full-name`:
357-
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.
356+
* `--formula`:
357+
List only formulae. `This is the default action on non TTY.`
358+
* `--cask`:
359+
List only casks, or *`cask`* if provided.
358360
* `--unbrewed`:
359361
List files in Homebrew's prefix not installed by Homebrew.
362+
* `--full-name`:
363+
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.
360364
* `--versions`:
361365
Show the version number for installed formulae, or only the specified formulae if *`formula`* are provided.
362366
* `--multiple`:
363367
Only show formulae with multiple versions installed.
364368
* `--pinned`:
365369
Show the versions of pinned formulae, or only the specified (pinned) formulae if *`formula`* are provided. See also `pin`, `unpin`.
366-
* `--formula`:
367-
List only formulae. `This is the default action on non TTY.`
368-
* `--cask`:
369-
List only casks, or *`cask`* if provided.
370370
* `-1`:
371371
Force output to be one entry per line. This is the default when output is not to a terminal.
372372
* `-l`:
373-
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.
373+
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.
374374
* `-r`:
375-
Reverse the order of the sort to list the oldest entries first.
375+
Reverse the order of the formulae sort to list the oldest entries first.
376376
* `-t`:
377-
Sort by time modified, listing most recently modified first.
377+
Sort formulae by time modified, listing most recently modified first.
378378

379379
### `log` [*`options`*] [*`formula`*]
380380

manpages/brew.1

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "BREW" "1" "October 2020" "Homebrew" "brew"
4+
.TH "BREW" "1" "November 2020" "Homebrew" "brew"
55
.
66
.SH "NAME"
77
\fBbrew\fR \- The Missing Package Manager for macOS
@@ -512,14 +512,22 @@ List all installed formulae or casks
512512
If \fIformula\fR is provided, summarise the paths within its current keg\.
513513
.
514514
.TP
515-
\fB\-\-full\-name\fR
516-
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\.
515+
\fB\-\-formula\fR
516+
List only formulae\. \fBThis is the default action on non TTY\.\fR
517+
.
518+
.TP
519+
\fB\-\-cask\fR
520+
List only casks, or \fIcask\fR if provided\.
517521
.
518522
.TP
519523
\fB\-\-unbrewed\fR
520524
List files in Homebrew\'s prefix not installed by Homebrew\.
521525
.
522526
.TP
527+
\fB\-\-full\-name\fR
528+
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\.
529+
.
530+
.TP
523531
\fB\-\-versions\fR
524532
Show the version number for installed formulae, or only the specified formulae if \fIformula\fR are provided\.
525533
.
@@ -532,28 +540,20 @@ Only show formulae with multiple versions installed\.
532540
Show the versions of pinned formulae, or only the specified (pinned) formulae if \fIformula\fR are provided\. See also \fBpin\fR, \fBunpin\fR\.
533541
.
534542
.TP
535-
\fB\-\-formula\fR
536-
List only formulae\. \fBThis is the default action on non TTY\.\fR
537-
.
538-
.TP
539-
\fB\-\-cask\fR
540-
List only casks, or \fIcask\fR if provided\.
541-
.
542-
.TP
543543
\fB\-1\fR
544544
Force output to be one entry per line\. This is the default when output is not to a terminal\.
545545
.
546546
.TP
547547
\fB\-l\fR
548-
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\.
548+
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\.
549549
.
550550
.TP
551551
\fB\-r\fR
552-
Reverse the order of the sort to list the oldest entries first\.
552+
Reverse the order of the formulae sort to list the oldest entries first\.
553553
.
554554
.TP
555555
\fB\-t\fR
556-
Sort by time modified, listing most recently modified first\.
556+
Sort formulae by time modified, listing most recently modified first\.
557557
.
558558
.SS "\fBlog\fR [\fIoptions\fR] [\fIformula\fR]"
559559
Show the \fBgit log\fR for \fIformula\fR, or show the log for the Homebrew repository if no formula is provided\.

0 commit comments

Comments
 (0)