Port Homebrew::Cmd::CompletionsCmd

This commit is contained in:
Douglas Eichelberger 2024-03-29 16:26:55 -07:00
parent 02e2772e9d
commit b97f9b22e2
2 changed files with 35 additions and 37 deletions

View File

@ -1,15 +1,13 @@
# typed: strict
# frozen_string_literal: true
require "cli/parser"
require "abstract_command"
require "completions"
module Homebrew
module_function
sig { returns(CLI::Parser) }
def completions_args
Homebrew::CLI::Parser.new do
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>.
@ -23,12 +21,9 @@ module Homebrew
named_args %w[state link unlink], max: 1
end
end
sig { void }
def completions
args = completions_args.parse
sig { override.void }
def run
case args.named.first
when nil, "state"
if Completions.link_completions?
@ -47,3 +42,5 @@ module Homebrew
end
end
end
end
end

View File

@ -1,8 +1,9 @@
# frozen_string_literal: true
require "cmd/completions"
require "cmd/shared_examples/args_parse"
RSpec.describe "brew completions" do
RSpec.describe Homebrew::Cmd::CompletionsCmd do
it_behaves_like "parseable arguments"
it "runs the status subcommand correctly", :integration_test do