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
# frozen_string_literal: true
require "abstract_command"
require "fileutils"
require "tap"
require "cli/parser"
module Homebrew
sig { returns(CLI::Parser) }
def self.tap_new_args
Homebrew::CLI::Parser.new do
module DevCmd
class TapNew < AbstractCommand
include FileUtils
cmd_args do
usage_banner "`tap-new` [<options>] <user>`/`<repo>"
description <<~EOS
Generate the template files for a new tap.
@ -25,15 +29,13 @@ module Homebrew
named_args :tap, number: 1
end
end
def self.tap_new
args = tap_new_args.parse
sig { override.void }
def run
label = args.pull_label || "pr-pull"
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)
titleized_user = tap.user.dup
@ -172,11 +174,15 @@ module Homebrew
EOS
end
def self.write_path(tap, filename, content)
private
def write_path(tap, filename, content)
path = tap.path/filename
tap.path.mkpath
odie "#{path} already exists" if path.exist?
path.write content
end
end
end
end

View File

@ -1,8 +1,9 @@
# frozen_string_literal: true
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 "initializes a new tap with a README file and GitHub Actions CI", :integration_test do