Merge pull request #172137 from Homebrew/bump-exploitdb-2024-05-20
[homebrew-core.git] / cmd / aspell-dictionaries.rb
blob45a1ac5631df3033645e90757390735afd71a979
1 # frozen_string_literal: true
3 require "cli/parser"
4 require "resource"
5 require "formula"
7 module Homebrew
8   module_function
10   def aspell_dictionaries_args
11     Homebrew::CLI::Parser.new do
12       usage_banner <<~EOS
13         `aspell-dictionaries`
15         Generates the new dictionaries for the `aspell` formula.
16       EOS
17     end
18   end
20   def aspell_dictionaries
21     aspell_dictionaries_args.parse
23     dictionary_url = "https://ftp.gnu.org/gnu/aspell/dict"
24     dictionary_mirror = "https://ftpmirror.gnu.org/aspell/dict"
25     languages = {}
27     index_output, = Utils::Curl.curl_output("#{dictionary_url}/0index.html")
28     index_output.split("<tr><td>").each do |line|
29       next unless line.start_with?("<a ")
31       _, language, _, path, = line.split('"')
32       language.tr!("-", "_")
33       languages[language] = path
34     end
36     resources = languages.map do |language, path|
37       r = Resource.new(language)
38       r.owner = Formula["aspell"]
39       r.url "#{dictionary_url}/#{path}"
40       r.mirror "#{dictionary_mirror}/#{path}"
41       r
42     end
44     output = resources.map do |resource|
45       resource.fetch(verify_download_integrity: false)
47       <<-EOS
48         resource "#{resource.name}" do
49           url "#{resource.url}"
50           mirror "#{resource.mirrors.first}"
51           sha256 "#{resource.cached_download.sha256}"
52         end
54       EOS
55     end
57     puts output
58   end
59 end