Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev-cmd/create: add types #16905

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions Library/Homebrew/dev-cmd/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
end

# Create a formula from a tarball URL.
sig { void }
def create
args = create_args.parse

Expand All @@ -82,6 +83,7 @@
exec_editor path
end

sig { params(args: CLI::Args).returns(Pathname) }
def create_cask(args:)
url = args.named.first
name = if args.set_name.blank?
Expand All @@ -91,7 +93,7 @@
else
args.set_name
end
token = Cask::Utils.token_from(name)
token = Cask::Utils.token_from(T.must(name))

Check warning on line 96 in Library/Homebrew/dev-cmd/create.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/create.rb#L96

Added line #L96 was not covered by tests

cask_tap = Tap.fetch(args.tap || "homebrew/cask")
raise TapUnavailableError, cask_tap.name unless cask_tap.installed?
Expand All @@ -101,7 +103,7 @@
raise Cask::CaskAlreadyCreatedError, token if cask_path.exist?

version = if args.set_version
Version.new(args.set_version)
Version.new(T.must(args.set_version))
else
Version.detect(url.gsub(token, "").gsub(/x86(_64)?/, ""))
end
Expand Down Expand Up @@ -153,6 +155,7 @@
cask_path
end

sig { params(args: CLI::Args).returns(Pathname) }
def create_formula(args:)
mode = if args.autotools?
:autotools
Expand Down Expand Up @@ -229,6 +232,7 @@
path
end

sig { returns(T.nilable(String)) }
def __gets
gots = $stdin.gets.chomp
gots.empty? ? nil : gots
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/formula_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def verify
raise TapUnavailableError, @tap.name unless @tap.installed?
end

sig { params(url: String).returns(T.nilable(String)) }
def self.name_from_url(url)
stem = Pathname.new(url).stem
# special cases first
Expand All @@ -47,6 +48,7 @@ def self.name_from_url(url)
end
end

sig { void }
def parse_url
@name = FormulaCreator.name_from_url(@url) if @name.blank?
odebug "name_from_url: #{@name}"
Expand All @@ -65,6 +67,7 @@ def parse_url
end
end

sig { returns(Pathname) }
def write_formula!
raise ArgumentError, "name is blank!" if @name.blank?
raise ArgumentError, "tap is blank!" if @tap.blank?
Expand Down