create: Use Parser to parse args
This commit is contained in:
parent
cd6c990919
commit
f60751d91c
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
require "formula"
|
require "formula"
|
||||||
require "missing_formula"
|
require "missing_formula"
|
||||||
|
require "cli_parser"
|
||||||
require "digest"
|
require "digest"
|
||||||
require "erb"
|
require "erb"
|
||||||
|
|
||||||
@ -29,6 +30,19 @@ module Homebrew
|
|||||||
|
|
||||||
# Create a formula from a tarball URL
|
# Create a formula from a tarball URL
|
||||||
def create
|
def create
|
||||||
|
Homebrew::CLI::Parser.parse do
|
||||||
|
switch "--autotools"
|
||||||
|
switch "--cmake"
|
||||||
|
switch "--meson"
|
||||||
|
switch "--no-fetch"
|
||||||
|
switch "--HEAD"
|
||||||
|
switch :force
|
||||||
|
switch :verbose
|
||||||
|
switch :debug
|
||||||
|
flag "--set-name="
|
||||||
|
flag "--set-version="
|
||||||
|
flag "--tag="
|
||||||
|
end
|
||||||
raise UsageError if ARGV.named.empty?
|
raise UsageError if ARGV.named.empty?
|
||||||
|
|
||||||
# Ensure that the cache exists so we can fetch the tarball
|
# Ensure that the cache exists so we can fetch the tarball
|
||||||
@ -36,9 +50,9 @@ module Homebrew
|
|||||||
|
|
||||||
url = ARGV.named.first # Pull the first (and only) url from ARGV
|
url = ARGV.named.first # Pull the first (and only) url from ARGV
|
||||||
|
|
||||||
version = ARGV.next if ARGV.include? "--set-version"
|
version = args.set_version
|
||||||
name = ARGV.next if ARGV.include? "--set-name"
|
name = args.set_name
|
||||||
tap = ARGV.next if ARGV.include? "--tap"
|
tap = args.tap
|
||||||
|
|
||||||
fc = FormulaCreator.new
|
fc = FormulaCreator.new
|
||||||
fc.name = name
|
fc.name = name
|
||||||
@ -47,11 +61,11 @@ module Homebrew
|
|||||||
raise TapUnavailableError, tap unless fc.tap.installed?
|
raise TapUnavailableError, tap unless fc.tap.installed?
|
||||||
fc.url = url
|
fc.url = url
|
||||||
|
|
||||||
fc.mode = if ARGV.include? "--cmake"
|
fc.mode = if args.cmake?
|
||||||
:cmake
|
:cmake
|
||||||
elsif ARGV.include? "--autotools"
|
elsif args.autotools?
|
||||||
:autotools
|
:autotools
|
||||||
elsif ARGV.include? "--meson"
|
elsif args.meson?
|
||||||
:meson
|
:meson
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -64,7 +78,7 @@ module Homebrew
|
|||||||
|
|
||||||
# Don't allow blacklisted formula, or names that shadow aliases,
|
# Don't allow blacklisted formula, or names that shadow aliases,
|
||||||
# unless --force is specified.
|
# unless --force is specified.
|
||||||
unless ARGV.force?
|
unless args.force?
|
||||||
if reason = MissingFormula.blacklisted_reason(fc.name)
|
if reason = MissingFormula.blacklisted_reason(fc.name)
|
||||||
raise "#{fc.name} is blacklisted for creation.\n#{reason}\nIf you really want to create this formula use --force."
|
raise "#{fc.name} is blacklisted for creation.\n#{reason}\nIf you really want to create this formula use --force."
|
||||||
end
|
end
|
||||||
@ -89,7 +103,6 @@ module Homebrew
|
|||||||
gots = $stdin.gets.chomp
|
gots = $stdin.gets.chomp
|
||||||
gots.empty? ? nil : gots
|
gots.empty? ? nil : gots
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
class FormulaCreator
|
class FormulaCreator
|
||||||
attr_reader :url, :sha256, :desc, :homepage
|
attr_reader :url, :sha256, :desc, :homepage
|
||||||
@ -127,11 +140,11 @@ class FormulaCreator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def fetch?
|
def fetch?
|
||||||
!ARGV.include?("--no-fetch")
|
!Homebrew.args.no_fetch?
|
||||||
end
|
end
|
||||||
|
|
||||||
def head?
|
def head?
|
||||||
@head || ARGV.build_head?
|
@head || Homebrew.args.head?
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate!
|
def generate!
|
||||||
@ -239,3 +252,4 @@ class FormulaCreator
|
|||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user