lib/tapioca/commands/annotations.rb in tapioca-0.9.3 vs lib/tapioca/commands/annotations.rb in tapioca-0.9.4

- old
+ new

@@ -86,12 +86,11 @@ indexes[uri] = index repo_number += 1 end if indexes.empty? - say_error("\nCan't fetch annotations without sources (no index fetched)", :bold, :red) - exit(1) + raise Thor::Error, set_color("Can't fetch annotations without sources (no index fetched)", :bold, :red) end indexes end @@ -110,16 +109,19 @@ def fetch_annotations(gem_names) say("Fetching gem annotations from central repository... ", [:blue, :bold]) fetchable_gems = T.let(Hash.new { |h, k| h[k] = [] }, T::Hash[String, T::Array[String]]) gem_names.each_with_object(fetchable_gems) do |gem_name, hash| - @indexes.each { |uri, index| T.must(hash[gem_name]) << uri if index.has_gem?(gem_name) } + @indexes.each do |uri, index| + T.must(hash[gem_name]) << uri if index.has_gem?(gem_name) + end end if fetchable_gems.empty? say(" Nothing to do") - exit(0) + + return [] end say("\n") fetched_gems = fetchable_gems.select { |gem_name, repo_uris| fetch_annotation(repo_uris, gem_name) } say("\nDone", :green) @@ -191,10 +193,11 @@ # DO NOT EDIT MANUALLY # This file was pulled from a central RBI files repository. # Please run `#{default_command(:annotations)}` to update it. COMMENT - contents = content.split("\n") + # Split contents into newlines and ensure trailing empty lines are included + contents = content.split("\n", -1) if contents[0]&.start_with?("# typed:") && contents[1]&.empty? contents.insert(2, header).join("\n") else say_error("Couldn't insert file header for content: #{content} due to unexpected file format") content