Port Homebrew::DevCmd::Create

This commit is contained in:
Douglas Eichelberger 2024-03-21 08:08:53 -07:00
parent d704e007c7
commit 9297a850aa
3 changed files with 225 additions and 224 deletions

View File

@ -1,6 +1,7 @@
# typed: true
# frozen_string_literal: true
require "abstract_command"
require "cli/parser"
require "csv"

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "formula"
@ -9,11 +9,9 @@ require "utils/pypi"
require "cask/cask_loader"
module Homebrew
module_function
sig { returns(CLI::Parser) }
def create_args
Homebrew::CLI::Parser.new do
module DevCmd
class Create < AbstractCommand
cmd_args do
description <<~EOS
Generate a formula or, with `--cask`, a cask for the downloadable file at <URL>
and open it in the editor. Homebrew will attempt to automatically derive the
@ -67,24 +65,23 @@ module Homebrew
named_args :url, number: 1
end
end
# Create a formula from a tarball URL.
sig { void }
def create
args = create_args.parse
sig { override.void }
def run
path = if args.cask?
create_cask(args:)
create_cask
else
create_formula(args:)
create_formula
end
exec_editor path
end
sig { params(args: CLI::Args).returns(Pathname) }
def create_cask(args:)
private
sig { returns(Pathname) }
def create_cask
url = args.named.first
name = if args.set_name.blank?
stem = Pathname.new(url).stem.rpartition("=").last
@ -155,8 +152,8 @@ module Homebrew
cask_path
end
sig { params(args: CLI::Args).returns(Pathname) }
def create_formula(args:)
sig { returns(Pathname) }
def create_formula
mode = if args.autotools?
:autotools
elsif args.cmake?
@ -237,4 +234,6 @@ module Homebrew
gots = $stdin.gets.chomp
gots.empty? ? nil : gots
end
end
end
end

View File

@ -1,12 +1,13 @@
# frozen_string_literal: true
require "cmd/shared_examples/args_parse"
require "dev-cmd/create"
RSpec.describe "brew create" do
RSpec.describe Homebrew::DevCmd::Create do
let(:url) { "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" }
let(:formula_file) { CoreTap.instance.new_formula_path("testball") }
it_behaves_like "parseable arguments"
it_behaves_like "parseable arguments", argv: ["foo"]
it "creates a new Formula file for a given URL", :integration_test do
brew "create", "--set-name=Testball", url, "HOMEBREW_EDITOR" => "/bin/cat"