Port Homebrew::DevCmd::Create
This commit is contained in:
parent
d704e007c7
commit
9297a850aa
@ -1,6 +1,7 @@
|
|||||||
# typed: true
|
# typed: true
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "abstract_command"
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
require "csv"
|
require "csv"
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
# typed: true
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "formula"
|
require "formula"
|
||||||
@ -9,11 +9,9 @@ require "utils/pypi"
|
|||||||
require "cask/cask_loader"
|
require "cask/cask_loader"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module DevCmd
|
||||||
|
class Create < AbstractCommand
|
||||||
sig { returns(CLI::Parser) }
|
cmd_args do
|
||||||
def create_args
|
|
||||||
Homebrew::CLI::Parser.new do
|
|
||||||
description <<~EOS
|
description <<~EOS
|
||||||
Generate a formula or, with `--cask`, a cask for the downloadable file at <URL>
|
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
|
and open it in the editor. Homebrew will attempt to automatically derive the
|
||||||
@ -67,24 +65,23 @@ module Homebrew
|
|||||||
|
|
||||||
named_args :url, number: 1
|
named_args :url, number: 1
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# Create a formula from a tarball URL.
|
# Create a formula from a tarball URL.
|
||||||
sig { void }
|
sig { override.void }
|
||||||
def create
|
def run
|
||||||
args = create_args.parse
|
|
||||||
|
|
||||||
path = if args.cask?
|
path = if args.cask?
|
||||||
create_cask(args:)
|
create_cask
|
||||||
else
|
else
|
||||||
create_formula(args:)
|
create_formula
|
||||||
end
|
end
|
||||||
|
|
||||||
exec_editor path
|
exec_editor path
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(args: CLI::Args).returns(Pathname) }
|
private
|
||||||
def create_cask(args:)
|
|
||||||
|
sig { returns(Pathname) }
|
||||||
|
def create_cask
|
||||||
url = args.named.first
|
url = args.named.first
|
||||||
name = if args.set_name.blank?
|
name = if args.set_name.blank?
|
||||||
stem = Pathname.new(url).stem.rpartition("=").last
|
stem = Pathname.new(url).stem.rpartition("=").last
|
||||||
@ -155,8 +152,8 @@ module Homebrew
|
|||||||
cask_path
|
cask_path
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(args: CLI::Args).returns(Pathname) }
|
sig { returns(Pathname) }
|
||||||
def create_formula(args:)
|
def create_formula
|
||||||
mode = if args.autotools?
|
mode = if args.autotools?
|
||||||
:autotools
|
:autotools
|
||||||
elsif args.cmake?
|
elsif args.cmake?
|
||||||
@ -237,4 +234,6 @@ module Homebrew
|
|||||||
gots = $stdin.gets.chomp
|
gots = $stdin.gets.chomp
|
||||||
gots.empty? ? nil : gots
|
gots.empty? ? nil : gots
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cmd/shared_examples/args_parse"
|
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(:url) { "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" }
|
||||||
let(:formula_file) { CoreTap.instance.new_formula_path("testball") }
|
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
|
it "creates a new Formula file for a given URL", :integration_test do
|
||||||
brew "create", "--set-name=Testball", url, "HOMEBREW_EDITOR" => "/bin/cat"
|
brew "create", "--set-name=Testball", url, "HOMEBREW_EDITOR" => "/bin/cat"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user