dev-cmd/create: also prompt for name with --cask

This commit is contained in:
EricFromCanada 2022-12-05 16:07:11 -05:00
parent 7ecc079cc2
commit 8f445de261
No known key found for this signature in database
GPG Key ID: 179D9CDDDB814168
2 changed files with 17 additions and 14 deletions

View File

@ -85,11 +85,15 @@ module Homebrew
end
def create_cask(args:)
raise UsageError, "The `--set-name` flag is required for creating casks." if args.set_name.blank?
url = args.named.first
name = args.set_name
token = Cask::Utils.token_from(args.set_name)
name = if args.set_name.blank?
stem = Pathname.new(url).stem.rpartition("=").last
print "Cask name [#{stem}]: "
__gets || stem
else
args.set_name
end
token = Cask::Utils.token_from(name)
cask_tap = Tap.fetch(args.tap || "homebrew/cask")
raise TapUnavailableError, args.tap unless cask_tap.installed?
@ -139,13 +143,19 @@ module Homebrew
def create_formula(args:)
fc = FormulaCreator.new(args)
fc.name = args.set_name
fc.name = if args.set_name.blank?
stem = Pathname.new(args.named.first).stem.rpartition("=").last
print "Formula name [#{stem}]: "
__gets || stem
else
args.set_name
end
fc.version = args.set_version
fc.license = args.set_license
fc.tap = Tap.fetch(args.tap || "homebrew/core")
raise TapUnavailableError, args.tap unless fc.tap.installed?
fc.url = args.named.first # Pull the first (and only) URL from ARGV
fc.url = args.named.first
fc.mode = if args.autotools?
:autotools
@ -169,13 +179,6 @@ module Homebrew
:rust
end
if fc.name.nil? || fc.name.strip.empty?
stem = Pathname.new(fc.url).stem.rpartition("=").last
print "Formula name [#{stem}]: "
fc.name = __gets || stem
fc.update_path
end
# Check for disallowed formula, or names that shadow aliases,
# unless --force is specified.
unless args.force?

View File

@ -10,7 +10,7 @@ describe "brew create" do
it_behaves_like "parseable arguments"
it "creates a new Formula file for a given URL", :integration_test do
brew "create", url, "HOMEBREW_EDITOR" => "/bin/cat"
brew "create", "--set-name=Testball", url, "HOMEBREW_EDITOR" => "/bin/cat"
expect(formula_file).to exist
expect(formula_file.read).to match(%Q(sha256 "#{TESTBALL_SHA256}"))