Class: Tapioca::Cli

Inherits:
Thor
  • Object
show all
Includes:
CliHelper, ConfigHelper, EnvHelper
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 EnvHelper

#set_environment

Methods included from ConfigHelper

#initialize, #options

Methods included from CliHelper

#netrc_file, #rbi_formatter, #say_error

Instance Method Details

#__print_versionObject



322
323
324
# File 'lib/tapioca/cli.rb', line 322

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

#annotationsObject



304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/tapioca/cli.rb', line 304

def annotations
  if !options[:netrc] && options[:netrc_file]
    say_error("Options `--no-netrc` and `--netrc-file` can't be used together", :bold, :red)
    exit(1)
  end

  command = Commands::Annotations.new(
    central_repo_root_uris: options[:sources],
    auth: options[:auth],
    netrc_file: netrc_file(options),
    typed_overrides: options[:typed_overrides]
  )
  command.execute
end

#check_shimsObject



279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/tapioca/cli.rb', line 279

def check_shims
  command = Commands::CheckShims.new(
    gem_rbi_dir: options[:gem_rbi_dir],
    dsl_rbi_dir: options[:dsl_rbi_dir],
    shim_rbi_dir: options[:shim_rbi_dir],
    annotations_rbi_dir: options[:annotations_rbi_dir],
    todo_rbi_file: options[:todo_rbi_file],
    payload: options[:payload],
    number_of_workers: options[:workers]
  )
  command.execute
end

#configureObject



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

def configure
  command = Commands::Configure.new(
    sorbet_config: SORBET_CONFIG_FILE,
    tapioca_config: options[:config],
    default_postrequire: options[:postrequire]
  )
  command.execute
end

#dsl(*constants) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/tapioca/cli.rb', line 119

def dsl(*constants)
  set_environment(options)

  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



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/tapioca/cli.rb', line 224

def gem(*gems)
  Tapioca.silence_warnings do
    set_environment(options)

    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],
      include_doc: options[:doc],
      include_loc: options[:loc],
      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, exclude: options[:exclude])
    else
      command.execute
    end
  end
end

#initObject



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

def init
  invoke(:configure)
  invoke(:annotations)
  invoke(:gem)
  invoke(:todo)

  print_init_next_steps
end

#requireObject



47
48
49
50
51
52
53
54
55
# File 'lib/tapioca/cli.rb', line 47

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



66
67
68
69
70
71
72
73
74
# File 'lib/tapioca/cli.rb', line 66

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