lib/tapioca/cli.rb in tapioca-0.7.3 vs lib/tapioca/cli.rb in tapioca-0.8.0
- old
+ new
@@ -3,10 +3,11 @@
module Tapioca
class Cli < Thor
include CliHelper
include ConfigHelper
+ include SorbetHelper
include ShimsHelper
FILE_HEADER_OPTION_DESC = "Add a \"This file is generated\" header on top of each generated RBI file"
class_option :config,
@@ -87,11 +88,11 @@
default: false,
desc: "Verifies RBIs are up-to-date"
option :quiet,
aliases: ["-q"],
type: :boolean,
- desc: "Supresses file creation output",
+ desc: "Suppresses file creation output",
default: false
option :workers,
aliases: ["-w"],
type: :numeric,
desc: "EXPERIMENTAL: Number of parallel workers to use when generating RBIs",
@@ -169,11 +170,11 @@
desc: "Verify RBIs are up-to-date",
default: false
option :doc,
type: :boolean,
desc: "Include YARD documentation from sources when generating RBIs. Warning: this might be slow",
- default: false
+ default: true
option :exported_gem_rbis,
type: :boolean,
desc: "Include RBIs found in the `rbi/` directory of the gem",
default: true
option :workers,
@@ -240,36 +241,72 @@
desc "check-shims", "check duplicated definitions in shim RBIs"
option :gem_rbi_dir, type: :string, desc: "Path to gem RBIs", default: DEFAULT_GEM_DIR
option :dsl_rbi_dir, type: :string, desc: "Path to DSL RBIs", default: DEFAULT_DSL_DIR
option :shim_rbi_dir, type: :string, desc: "Path to shim RBIs", default: DEFAULT_SHIM_DIR
+ option :payload, type: :boolean, desc: "Check shims against Sorbet's payload", default: true
def check_shims
index = RBI::Index.new
shim_rbi_dir = options[:shim_rbi_dir]
if !Dir.exist?(shim_rbi_dir) || Dir.empty?(shim_rbi_dir)
say("No shim RBIs to check", :green)
exit(0)
end
+ payload_path = T.let(nil, T.nilable(String))
+
+ if options[:payload]
+ if sorbet_supports?(:print_payload_sources)
+ Dir.mktmpdir do |dir|
+ payload_path = dir
+ result = sorbet("--no-config --print=payload-sources:#{payload_path}")
+
+ unless result.status
+ say_error("Sorbet failed to dump payload")
+ say_error(result.err)
+ exit(1)
+ end
+
+ index_payload(index, payload_path)
+ end
+ else
+ say_error("The version of Sorbet used in your Gemfile.lock does not support `--print=payload-sources`")
+ say_error("Current: v#{SORBET_GEM_SPEC.version}")
+ say_error("Required: #{FEATURE_REQUIREMENTS[:print_payload_sources]}")
+ exit(1)
+ end
+ end
+
index_rbis(index, "shim", shim_rbi_dir)
index_rbis(index, "gem", options[:gem_rbi_dir])
index_rbis(index, "dsl", options[:dsl_rbi_dir])
duplicates = duplicated_nodes_from_index(index, shim_rbi_dir)
unless duplicates.empty?
duplicates.each do |key, nodes|
say_error("\nDuplicated RBI for #{key}:", :red)
nodes.each do |node|
- say_error(" * #{node.loc}", :red)
+ node_loc = node.loc
+ next unless node_loc
+
+ loc_string = location_to_payload_url(node_loc, path_prefix: payload_path)
+ say_error(" * #{loc_string}", :red)
end
end
say_error("\nPlease remove the duplicated definitions from the #{shim_rbi_dir} directory.", :red)
exit(1)
end
say("\nNo duplicates found in shim RBIs", :green)
exit(0)
+ end
+
+ desc "annotations", "Pull gem annotations from a central RBI repository"
+ option :repo_uri, type: :string, desc: "Repository URI to pull annotations from", default: CENTRAL_REPO_ROOT_URI
+ def annotations
+ command = Commands::Annotations.new(central_repo_root_uri: options[:repo_uri])
+ command.execute
end
map ["--version", "-v"] => :__print_version
desc "--version, -v", "show version"