brew/Library/Homebrew/cmd/completions.rb

47 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2023-08-08 13:54:59 -07:00
# typed: strict
2021-01-08 11:10:24 -05:00
# frozen_string_literal: true
2024-03-29 16:26:55 -07:00
require "abstract_command"
2021-01-08 11:10:24 -05:00
require "completions"
module Homebrew
2024-03-29 16:26:55 -07:00
module Cmd
class CompletionsCmd < AbstractCommand
cmd_args do
description <<~EOS
Control whether Homebrew automatically links external tap shell completion files.
Read more at <https://docs.brew.sh/Shell-Completion>.
2021-01-08 11:10:24 -05:00
2024-03-29 16:26:55 -07:00
`brew completions` [`state`]:
Display the current state of Homebrew's completions.
2021-01-08 11:10:24 -05:00
2024-03-29 16:26:55 -07:00
`brew completions` (`link`|`unlink`):
Link or unlink Homebrew's completions.
EOS
2021-01-08 11:10:24 -05:00
2024-03-29 16:26:55 -07:00
named_args %w[state link unlink], max: 1
end
2021-01-08 11:10:24 -05:00
2024-03-29 16:26:55 -07:00
sig { override.void }
def run
case args.named.first
when nil, "state"
if Completions.link_completions?
puts "Completions are linked."
else
puts "Completions are not linked."
end
when "link"
Completions.link!
puts "Completions are now linked."
when "unlink"
Completions.unlink!
puts "Completions are no longer linked."
else
raise UsageError, "unknown subcommand: #{args.named.first}"
end
2021-01-08 11:10:24 -05:00
end
end
end
end