| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2018-06-03 15:28:48 +05:30
										 |  |  | require "formula_creator" | 
					
						
							| 
									
										
										
										
											2017-03-18 17:02:08 +02:00
										 |  |  | require "missing_formula" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   def create_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       usage_banner <<~EOS | 
					
						
							| 
									
										
										
										
											2018-10-15 15:06:33 -04:00
										 |  |  |         `create` [<options>] <URL> | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |         Generate a formula for the downloadable file at <URL> and open it in the editor. | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |         Homebrew will attempt to automatically derive the formula name and version, but | 
					
						
							|  |  |  |         if it fails, you'll have to make your own template. The `wget` formula serves as | 
					
						
							|  |  |  |         a simple example. For the complete API, see: | 
					
						
							|  |  |  |         <http://www.rubydoc.info/github/Homebrew/brew/master/Formula> | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       EOS | 
					
						
							|  |  |  |       switch "--autotools", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Create a basic template for an Autotools-style build." | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       switch "--cmake", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Create a basic template for a CMake-style build." | 
					
						
							| 
									
										
										
										
											2020-06-25 17:17:42 +02:00
										 |  |  |       switch "--crystal", | 
					
						
							|  |  |  |              description: "Create a basic template for a Crystal build." | 
					
						
							| 
									
										
										
										
											2019-09-24 16:49:27 +02:00
										 |  |  |       switch "--go", | 
					
						
							|  |  |  |              description: "Create a basic template for a Go build." | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       switch "--meson", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Create a basic template for a Meson-style build." | 
					
						
							| 
									
										
										
										
											2019-09-25 21:52:16 +02:00
										 |  |  |       switch "--perl", | 
					
						
							|  |  |  |              description: "Create a basic template for a Perl build." | 
					
						
							| 
									
										
										
										
											2019-09-24 19:34:34 +02:00
										 |  |  |       switch "--python", | 
					
						
							|  |  |  |              description: "Create a basic template for a Python build." | 
					
						
							| 
									
										
										
										
											2020-03-21 15:32:52 +01:00
										 |  |  |       switch "--ruby", | 
					
						
							|  |  |  |              description: "Create a basic template for a Ruby build." | 
					
						
							| 
									
										
										
										
											2019-09-25 14:29:09 +02:00
										 |  |  |       switch "--rust", | 
					
						
							|  |  |  |              description: "Create a basic template for a Rust build." | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       switch "--no-fetch", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Homebrew will not download <URL> to the cache and will thus not add its SHA-256 "\ | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |                           "to the formula for you, nor will it check the GitHub API for GitHub projects "\ | 
					
						
							|  |  |  |                           "(to fill out its description and homepage)." | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |       switch "--HEAD", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Indicate that <URL> points to the package's repository rather than a file." | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       flag   "--set-name=", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Explicitly set the <name> of the new formula." | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       flag   "--set-version=", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Explicitly set the <version> of the new formula." | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       flag   "--tap=", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Generate the new formula within the given tap, specified as <user>`/`<repo>." | 
					
						
							| 
									
										
										
										
											2018-06-03 01:15:28 +05:30
										 |  |  |       switch :force | 
					
						
							|  |  |  |       switch :verbose | 
					
						
							|  |  |  |       switch :debug | 
					
						
							| 
									
										
										
										
											2020-06-25 17:17:42 +02:00
										 |  |  |       conflicts "--autotools", "--cmake", "--crystal", "--go", "--meson", "--perl", "--python", "--rust" | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:24 +00:00
										 |  |  |       named 1
 | 
					
						
							| 
									
										
										
										
											2018-06-03 01:15:28 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Create a formula from a tarball URL | 
					
						
							|  |  |  |   def create | 
					
						
							|  |  |  |     create_args.parse | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |     # Ensure that the cache exists so we can fetch the tarball | 
					
						
							|  |  |  |     HOMEBREW_CACHE.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:24 +00:00
										 |  |  |     url = args.named.first # Pull the first (and only) url from ARGV | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-03 01:15:28 +05:30
										 |  |  |     version = args.set_version | 
					
						
							|  |  |  |     name = args.set_name | 
					
						
							|  |  |  |     tap = args.tap | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     fc = FormulaCreator.new | 
					
						
							|  |  |  |     fc.name = name | 
					
						
							|  |  |  |     fc.version = version | 
					
						
							| 
									
										
										
										
											2016-06-23 23:23:41 -07:00
										 |  |  |     fc.tap = Tap.fetch(tap || "homebrew/core") | 
					
						
							|  |  |  |     raise TapUnavailableError, tap unless fc.tap.installed? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |     fc.url = url | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-03 01:15:28 +05:30
										 |  |  |     fc.mode = if args.cmake? | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |       :cmake | 
					
						
							| 
									
										
										
										
											2018-06-03 01:15:28 +05:30
										 |  |  |     elsif args.autotools? | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |       :autotools | 
					
						
							| 
									
										
										
										
											2018-06-03 01:15:28 +05:30
										 |  |  |     elsif args.meson? | 
					
						
							| 
									
										
										
										
											2016-12-19 21:51:57 +01:00
										 |  |  |       :meson | 
					
						
							| 
									
										
										
										
											2020-06-25 17:17:42 +02:00
										 |  |  |     elsif args.crystal? | 
					
						
							|  |  |  |       :crystal | 
					
						
							| 
									
										
										
										
											2019-09-24 16:49:27 +02:00
										 |  |  |     elsif args.go? | 
					
						
							|  |  |  |       :go | 
					
						
							| 
									
										
										
										
											2019-09-25 21:52:16 +02:00
										 |  |  |     elsif args.perl? | 
					
						
							|  |  |  |       :perl | 
					
						
							| 
									
										
										
										
											2019-09-24 19:34:34 +02:00
										 |  |  |     elsif args.python? | 
					
						
							|  |  |  |       :python | 
					
						
							| 
									
										
										
										
											2020-03-21 15:32:52 +01:00
										 |  |  |     elsif args.ruby? | 
					
						
							|  |  |  |       :ruby | 
					
						
							| 
									
										
										
										
											2019-09-25 14:29:09 +02:00
										 |  |  |     elsif args.rust? | 
					
						
							|  |  |  |       :rust | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-17 19:40:44 -05:00
										 |  |  |     if fc.name.nil? || fc.name.strip.empty? | 
					
						
							|  |  |  |       stem = Pathname.new(url).stem | 
					
						
							|  |  |  |       print "Formula name [#{stem}]: " | 
					
						
							|  |  |  |       fc.name = __gets || stem | 
					
						
							| 
									
										
										
										
											2016-06-23 23:23:41 -07:00
										 |  |  |       fc.update_path | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-06 21:10:16 +01:00
										 |  |  |     # Check for disallowed formula, or names that shadow aliases, | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |     # unless --force is specified. | 
					
						
							| 
									
										
										
										
											2018-06-03 01:15:28 +05:30
										 |  |  |     unless args.force? | 
					
						
							| 
									
										
										
										
											2020-06-06 21:10:16 +01:00
										 |  |  |       if reason = MissingFormula.disallowed_reason(fc.name) | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |         raise <<~EOS | 
					
						
							| 
									
										
										
										
											2020-06-06 21:10:16 +01:00
										 |  |  |           #{fc.name} is not allowed to be created. | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |           #{reason} | 
					
						
							|  |  |  |           If you really want to create this formula use --force. | 
					
						
							|  |  |  |         EOS | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if Formula.aliases.include? fc.name | 
					
						
							| 
									
										
										
										
											2014-06-22 15:00:15 -05:00
										 |  |  |         realname = Formulary.canonical_name(fc.name) | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |         raise <<~EOS | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |           The formula #{realname} is already aliased to #{fc.name} | 
					
						
							|  |  |  |           Please check that you are not creating a duplicate. | 
					
						
							|  |  |  |           To force creation use --force. | 
					
						
							| 
									
										
										
										
											2018-06-06 23:34:19 -04:00
										 |  |  |         EOS | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     fc.generate! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-29 14:53:01 -05:00
										 |  |  |     puts "Please run `brew audit --new-formula #{fc.name}` before submitting, thanks." | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |     exec_editor fc.path | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def __gets | 
					
						
							|  |  |  |     gots = $stdin.gets.chomp | 
					
						
							| 
									
										
										
										
											2016-09-11 17:41:51 +01:00
										 |  |  |     gots.empty? ? nil : gots | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |