Skip to content

Commit c8f491c

Browse files
committed
Convert remaining subcommands
- Small state/action commands should use the same parser API. - Keep the legacy analytics UUID command visible but marked for removal. - Refresh generated manpages and completions after all conversions.
1 parent 00b6e04 commit c8f491c

24 files changed

Lines changed: 848 additions & 170 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "abstract_subcommand"
5+
require "cli/parser"
6+
7+
Dir["#{__dir__}/subcommand/*.rb"].each do |subcommand|
8+
require "analytics/subcommand/#{File.basename(subcommand, ".rb")}"
9+
end
10+
11+
module Homebrew
12+
module Cmd
13+
class Analytics < Homebrew::AbstractCommand
14+
class << self
15+
sig { params(args: T.untyped).void }
16+
def dispatch(args)
17+
subcommand_class = Homebrew::AbstractSubcommand
18+
.subcommands_for(Homebrew::Cmd::Analytics)
19+
.find do |candidate|
20+
candidate.subcommand_name == args.subcommand
21+
end
22+
T.must(subcommand_class).new(args).run
23+
end
24+
end
25+
end
26+
end
27+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "abstract_subcommand"
5+
require "utils/analytics"
6+
7+
module Homebrew
8+
module Cmd
9+
class Analytics < Homebrew::AbstractCommand
10+
class OffSubcommand < Homebrew::AbstractSubcommand
11+
subcommand_args do
12+
usage_banner <<~EOS
13+
`brew analytics off`:
14+
Turn Homebrew's analytics off.
15+
EOS
16+
named_args :none
17+
end
18+
19+
sig { override.void }
20+
def run
21+
Utils::Analytics.disable!
22+
end
23+
end
24+
end
25+
end
26+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "abstract_subcommand"
5+
require "utils/analytics"
6+
7+
module Homebrew
8+
module Cmd
9+
class Analytics < Homebrew::AbstractCommand
10+
class OnSubcommand < Homebrew::AbstractSubcommand
11+
subcommand_args do
12+
usage_banner <<~EOS
13+
`brew analytics on`:
14+
Turn Homebrew's analytics on.
15+
EOS
16+
named_args :none
17+
end
18+
19+
sig { override.void }
20+
def run
21+
Utils::Analytics.enable!
22+
end
23+
end
24+
end
25+
end
26+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "abstract_subcommand"
5+
require "utils/analytics"
6+
7+
module Homebrew
8+
module Cmd
9+
class Analytics < Homebrew::AbstractCommand
10+
class RegenerateUuidSubcommand < Homebrew::AbstractSubcommand
11+
subcommand_args do
12+
usage_banner <<~EOS
13+
`brew analytics regenerate-uuid`:
14+
Delete Homebrew's legacy analytics UUID.
15+
EOS
16+
named_args :none
17+
end
18+
19+
sig { override.void }
20+
def run
21+
# odeprecated: remove in 5.2.0.
22+
Utils::Analytics.delete_uuid!
23+
opoo "Homebrew no longer uses an analytics UUID so this has been deleted!"
24+
puts "brew analytics regenerate-uuid is no longer necessary."
25+
end
26+
end
27+
end
28+
end
29+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "abstract_subcommand"
5+
require "utils/analytics"
6+
7+
module Homebrew
8+
module Cmd
9+
class Analytics < Homebrew::AbstractCommand
10+
class StateSubcommand < Homebrew::AbstractSubcommand
11+
subcommand_args default: true do
12+
usage_banner <<~EOS
13+
`brew analytics` [`state`]:
14+
Display the current state of Homebrew's analytics.
15+
EOS
16+
named_args :none
17+
end
18+
19+
sig { override.void }
20+
def run
21+
if Utils::Analytics.disabled?
22+
puts "InfluxDB analytics are disabled."
23+
else
24+
puts "InfluxDB analytics are enabled."
25+
end
26+
puts "Google Analytics were destroyed."
27+
end
28+
end
29+
end
30+
end
31+
end

Library/Homebrew/cmd/analytics.rb

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,22 @@
66
module Homebrew
77
module Cmd
88
class Analytics < AbstractCommand
9+
require "analytics/subcommand"
10+
911
cmd_args do
10-
description <<~EOS
12+
usage_banner <<~EOS
13+
`analytics` [<subcommand>]
14+
1115
Control Homebrew's anonymous aggregate user behaviour analytics.
1216
Read more at <https://docs.brew.sh/Analytics>.
13-
14-
`brew analytics` [`state`]:
15-
Display the current state of Homebrew's analytics.
16-
17-
`brew analytics` (`on`|`off`):
18-
Turn Homebrew's analytics on or off respectively.
1917
EOS
2018

21-
named_args %w[state on off regenerate-uuid], max: 1
19+
Homebrew::AbstractSubcommand.define_all(self, command: Homebrew::Cmd::Analytics)
2220
end
2321

2422
sig { override.void }
2523
def run
26-
case args.named.first
27-
when nil, "state"
28-
if Utils::Analytics.disabled?
29-
puts "InfluxDB analytics are disabled."
30-
else
31-
puts "InfluxDB analytics are enabled."
32-
end
33-
puts "Google Analytics were destroyed."
34-
when "on"
35-
Utils::Analytics.enable!
36-
when "off"
37-
Utils::Analytics.disable!
38-
when "regenerate-uuid"
39-
Utils::Analytics.delete_uuid!
40-
opoo "Homebrew no longer uses an analytics UUID so this has been deleted!"
41-
puts "brew analytics regenerate-uuid is no longer necessary."
42-
else
43-
raise UsageError, "unknown subcommand: #{args.named.first}"
44-
end
24+
Homebrew::Cmd::Analytics.dispatch(args)
4525
end
4626
end
4727
end

Library/Homebrew/cmd/completions.rb

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,22 @@
77
module Homebrew
88
module Cmd
99
class CompletionsCmd < AbstractCommand
10+
require "completions/subcommand"
11+
1012
cmd_args do
11-
description <<~EOS
13+
usage_banner <<~EOS
14+
`completions` [<subcommand>]
15+
1216
Control whether Homebrew automatically links external tap shell completion files.
1317
Read more at <https://docs.brew.sh/Shell-Completion>.
14-
15-
`brew completions` [`state`]:
16-
Display the current state of Homebrew's completions.
17-
18-
`brew completions` (`link`|`unlink`):
19-
Link or unlink Homebrew's completions.
2018
EOS
2119

22-
named_args %w[state link unlink], max: 1
20+
Homebrew::AbstractSubcommand.define_all(self, command: Homebrew::Cmd::CompletionsCmd)
2321
end
2422

2523
sig { override.void }
2624
def run
27-
case args.named.first
28-
when nil, "state"
29-
if Completions.link_completions?
30-
puts "Completions are linked."
31-
else
32-
puts "Completions are not linked."
33-
end
34-
when "link"
35-
Completions.link!
36-
puts "Completions are now linked."
37-
when "unlink"
38-
Completions.unlink!
39-
puts "Completions are no longer linked."
40-
else
41-
raise UsageError, "unknown subcommand: #{args.named.first}"
42-
end
25+
Homebrew::Cmd::CompletionsCmd.dispatch(args)
4326
end
4427
end
4528
end

Library/Homebrew/cmd/developer.rb

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,23 @@
66
module Homebrew
77
module Cmd
88
class Developer < AbstractCommand
9+
require "developer/subcommand"
10+
911
cmd_args do
10-
description <<~EOS
12+
usage_banner <<~EOS
13+
`developer` [<subcommand>]
14+
1115
Control Homebrew's developer mode. When developer mode is enabled,
1216
`brew update` will update Homebrew to the latest commit on the `main`
1317
branch instead of the latest stable version along with some other behaviour changes.
14-
15-
`brew developer` [`state`]:
16-
Display the current state of Homebrew's developer mode.
17-
18-
`brew developer` (`on`|`off`):
19-
Turn Homebrew's developer mode on or off respectively.
2018
EOS
2119

22-
named_args %w[state on off], max: 1
20+
Homebrew::AbstractSubcommand.define_all(self, command: Homebrew::Cmd::Developer)
2321
end
2422

2523
sig { override.void }
2624
def run
27-
case args.named.first
28-
when nil, "state"
29-
if Homebrew::EnvConfig.developer?
30-
puts "Developer mode is enabled because #{Tty.bold}HOMEBREW_DEVELOPER#{Tty.reset} is set."
31-
elsif Homebrew::EnvConfig.devcmdrun?
32-
puts "Developer mode is enabled because a developer command or `brew developer on` was run."
33-
else
34-
puts "Developer mode is disabled."
35-
end
36-
if Homebrew::EnvConfig.developer? || Homebrew::EnvConfig.devcmdrun?
37-
if Homebrew::EnvConfig.update_to_tag?
38-
puts "However, `brew update` will update to the latest stable tag because " \
39-
"#{Tty.bold}HOMEBREW_UPDATE_TO_TAG#{Tty.reset} is set."
40-
else
41-
puts "`brew update` will update to the latest commit on the `main` branch."
42-
end
43-
else
44-
puts "`brew update` will update to the latest stable tag."
45-
end
46-
when "on"
47-
Homebrew::Settings.write "devcmdrun", true
48-
if Homebrew::EnvConfig.update_to_tag?
49-
puts "To fully enable developer mode, you must unset #{Tty.bold}HOMEBREW_UPDATE_TO_TAG#{Tty.reset}."
50-
end
51-
when "off"
52-
Homebrew::Settings.delete "devcmdrun"
53-
if Homebrew::EnvConfig.developer?
54-
puts "To fully disable developer mode, you must unset #{Tty.bold}HOMEBREW_DEVELOPER#{Tty.reset}."
55-
end
56-
else
57-
raise UsageError, "unknown subcommand: #{args.named.first}"
58-
end
25+
Homebrew::Cmd::Developer.dispatch(args)
5926
end
6027
end
6128
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "abstract_subcommand"
5+
require "cli/parser"
6+
7+
Dir["#{__dir__}/subcommand/*.rb"].each do |subcommand|
8+
require "completions/subcommand/#{File.basename(subcommand, ".rb")}"
9+
end
10+
11+
module Homebrew
12+
module Cmd
13+
class CompletionsCmd < Homebrew::AbstractCommand
14+
class << self
15+
sig { params(args: T.untyped).void }
16+
def dispatch(args)
17+
subcommand_class = Homebrew::AbstractSubcommand
18+
.subcommands_for(Homebrew::Cmd::CompletionsCmd)
19+
.find do |candidate|
20+
candidate.subcommand_name == args.subcommand
21+
end
22+
T.must(subcommand_class).new(args).run
23+
end
24+
end
25+
end
26+
end
27+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "abstract_subcommand"
5+
require "completions"
6+
7+
module Homebrew
8+
module Cmd
9+
class CompletionsCmd < Homebrew::AbstractCommand
10+
class LinkSubcommand < Homebrew::AbstractSubcommand
11+
subcommand_args do
12+
usage_banner <<~EOS
13+
`brew completions link`:
14+
Link Homebrew's completions.
15+
EOS
16+
named_args :none
17+
end
18+
19+
sig { override.void }
20+
def run
21+
Completions.link!
22+
puts "Completions are now linked."
23+
end
24+
end
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)