Port Homebrew::DevCmd::TapNew

This commit is contained in:
Douglas Eichelberger 2024-03-21 21:47:55 -07:00
parent 0d04f198d2
commit e0519d736a
2 changed files with 151 additions and 144 deletions

View File

@ -1,13 +1,17 @@
# typed: true # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "abstract_command"
require "fileutils"
require "tap" require "tap"
require "cli/parser" require "cli/parser"
module Homebrew module Homebrew
sig { returns(CLI::Parser) } module DevCmd
def self.tap_new_args class TapNew < AbstractCommand
Homebrew::CLI::Parser.new do include FileUtils
cmd_args do
usage_banner "`tap-new` [<options>] <user>`/`<repo>" usage_banner "`tap-new` [<options>] <user>`/`<repo>"
description <<~EOS description <<~EOS
Generate the template files for a new tap. Generate the template files for a new tap.
@ -25,15 +29,13 @@ module Homebrew
named_args :tap, number: 1 named_args :tap, number: 1
end end
end
def self.tap_new
args = tap_new_args.parse
sig { override.void }
def run
label = args.pull_label || "pr-pull" label = args.pull_label || "pr-pull"
branch = args.branch || "main" branch = args.branch || "main"
tap = args.named.to_taps.first tap = args.named.to_taps.fetch(0)
odie "Invalid tap name '#{tap}'" unless tap.path.to_s.match?(HOMEBREW_TAP_PATH_REGEX) odie "Invalid tap name '#{tap}'" unless tap.path.to_s.match?(HOMEBREW_TAP_PATH_REGEX)
titleized_user = tap.user.dup titleized_user = tap.user.dup
@ -172,7 +174,9 @@ module Homebrew
EOS EOS
end end
def self.write_path(tap, filename, content) private
def write_path(tap, filename, content)
path = tap.path/filename path = tap.path/filename
tap.path.mkpath tap.path.mkpath
odie "#{path} already exists" if path.exist? odie "#{path} already exists" if path.exist?
@ -180,3 +184,5 @@ module Homebrew
path.write content path.write content
end end
end end
end
end

View File

@ -1,8 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cmd/shared_examples/args_parse" require "cmd/shared_examples/args_parse"
require "dev-cmd/tap-new"
RSpec.describe "brew tap-new" do RSpec.describe Homebrew::DevCmd::TapNew do
it_behaves_like "parseable arguments" it_behaves_like "parseable arguments"
it "initializes a new tap with a README file and GitHub Actions CI", :integration_test do it "initializes a new tap with a README file and GitHub Actions CI", :integration_test do