Class: Tapioca::Cli

Inherits:
Thor
  • Object
show all
Includes:
CliHelper, ConfigHelper, ShimsHelper
Defined in:
lib/tapioca/cli.rb

Constant Summary collapse

FILE_HEADER_OPTION_DESC =
"Add a \"This file is generated\" header on top of each generated RBI file"

Instance Attribute Summary

Attributes included from ConfigHelper

#command_name, #defaults

Instance Method Summary collapse

Methods included from ShimsHelper

#duplicated_nodes_from_index, #index_rbis

Methods included from ConfigHelper

#initialize, #options

Methods included from CliHelper

#rbi_formatter, #say_error

Instance Method Details

#__print_versionObject



277
278
279
# File 'lib/tapioca/cli.rb', line 277

def __print_version
  puts "Tapioca v#{Tapioca::VERSION}"
end

#check_shimsObject



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/tapioca/cli.rb', line 245

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

  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)
      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

#dsl(*constants) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/tapioca/cli.rb', line 103

def dsl(*constants)
  command = Commands::Dsl.new(
    requested_constants: constants,
    outpath: Pathname.new(options[:outdir]),
    only: options[:only],
    exclude: options[:exclude],
    file_header: options[:file_header],
    compiler_path: Tapioca::Dsl::Compilers::DIRECTORY,
    tapioca_path: TAPIOCA_DIR,
    should_verify: options[:verify],
    quiet: options[:quiet],
    verbose: options[:verbose],
    number_of_workers: options[:workers],
    rbi_formatter: rbi_formatter(options)
  )

  if options[:workers] != 1
    say(
      "Using more than one worker is experimental and might produce results that are not deterministic",
      :red
    )
  end

  Tapioca.silence_warnings do
    command.execute
  end
end

#gem(*gems) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/tapioca/cli.rb', line 197

def gem(*gems)
  Tapioca.silence_warnings do
    all = options[:all]
    verify = options[:verify]

    command = Commands::Gem.new(
      gem_names: all ? [] : gems,
      exclude: options[:exclude],
      prerequire: options[:prerequire],
      postrequire: options[:postrequire],
      typed_overrides: options[:typed_overrides],
      outpath: Pathname.new(options[:outdir]),
      file_header: options[:file_header],
      doc: options[:doc],
      include_exported_rbis: options[:exported_gem_rbis],
      number_of_workers: options[:workers],
      auto_strictness: options[:auto_strictness],
      dsl_dir: options[:dsl_dir],
      rbi_formatter: rbi_formatter(options)
    )

    raise MalformattedArgumentError, "Options '--all' and '--verify' are mutually exclusive" if all && verify

    unless gems.empty?
      raise MalformattedArgumentError, "Option '--all' must be provided without any other arguments" if all
      raise MalformattedArgumentError, "Option '--verify' must be provided without any other arguments" if verify
    end

    if options[:workers] != 1
      say(
        "Using more than one worker is experimental and might produce results that are not deterministic",
        :red
      )
    end

    if gems.empty? && !all
      command.sync(should_verify: verify)
    else
      command.execute
    end
  end
end

#initObject



25
26
27
28
29
30
31
32
# File 'lib/tapioca/cli.rb', line 25

def init
  command = Commands::Init.new(
    sorbet_config: SORBET_CONFIG_FILE,
    tapioca_config: TAPIOCA_CONFIG_FILE,
    default_postrequire: DEFAULT_POSTREQUIRE_FILE
  )
  command.execute
end

#requireObject



36
37
38
39
40
41
42
43
44
# File 'lib/tapioca/cli.rb', line 36

def require
  command = Commands::Require.new(
    requires_path: options[:postrequire],
    sorbet_config_path: SORBET_CONFIG_FILE
  )
  Tapioca.silence_warnings do
    command.execute
  end
end

#todoObject



55
56
57
58
59
60
61
62
63
# File 'lib/tapioca/cli.rb', line 55

def todo
  command = Commands::Todo.new(
    todo_file: options[:todo_file],
    file_header: options[:file_header]
  )
  Tapioca.silence_warnings do
    command.execute
  end
end