brew/Library/Homebrew/cmd/completions.rb

53 lines
1.1 KiB
Ruby
Raw Normal View History

2021-01-08 11:10:24 -05:00
# typed: true
# frozen_string_literal: true
require "cli/parser"
require "completions"
module Homebrew
extend T::Sig
module_function
sig { returns(CLI::Parser) }
def completions_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`completions` [<subcommand>]
Control whether Homebrew automatically links shell files.
Read more at <https://docs.brew.sh/Shell-Completion>.
`brew completions` [`state`]:
Display the current state of Homebrew's completions.
`brew completions` (`link`|`unlink`):
Link or unlink Homebrew's completions.
EOS
max_named 1
end
end
def completions
args = completions_args.parse
case args.named.first
when nil, "state"
if Completions.link_completions?
puts "Completions are not linked."
else
puts "Completions are 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
end
end