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



366
367
368
# File 'lib/tapioca/cli.rb', line 366

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

#annotationsObject



348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/tapioca/cli.rb', line 348

def annotations
  if !options[:netrc] && options[:netrc_file]
    raise Thor::Error, set_color("Options `--no-netrc` and `--netrc-file` can't be used together", :bold, :red)
  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.run
end

#check_shimsObject



320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/tapioca/cli.rb', line 320

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.run
end

#configureObject



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

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

#dsl(*constant_or_paths) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/tapioca/cli.rb', line 147

def dsl(*constant_or_paths)
  set_environment(options)

  # Assume anything starting with a capital letter or colon is a class, otherwise a path
  constants, paths = constant_or_paths.partition { |c| c =~ /\A[A-Z:]/ }

  command_args = {
    requested_constants: constants,
    requested_paths: paths.map { |p| Pathname.new(p) },
    outpath: Pathname.new(options[:outdir]),
    only: options[:only],
    exclude: options[:exclude],
    file_header: options[:file_header],
    tapioca_path: TAPIOCA_DIR,
    skip_constant: options[:skip_constant],
    quiet: options[:quiet],
    verbose: options[:verbose],
    number_of_workers: options[:workers],
    rbi_formatter: rbi_formatter(options),
    app_root: options[:app_root],
    halt_upon_load_error: options[:halt_upon_load_error],
    compiler_options: options[:compiler_options],
  }

  command = if options[:verify]
    Commands::DslVerify.new(**command_args)
  elsif options[:list_compilers]
    Commands::DslCompilerList.new(**command_args)
  else
    Commands::DslGenerate.new(**command_args)
  end

  command.run
end

#gem(*gems) ⇒ Object

Raises:

  • (MalformattedArgumentError)


264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/tapioca/cli.rb', line 264

def gem(*gems)
  set_environment(options)

  all = options[:all]
  verify = options[:verify]
  include_dependencies = options[:include_dependencies]

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

  if gems.empty?
    raise MalformattedArgumentError,
      "Option '--include-dependencies' must be provided with gems" if include_dependencies
  else
    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

  command_args = {
    gem_names: all ? [] : gems,
    exclude: options[:exclude],
    include_dependencies: options[:include_dependencies],
    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),
    halt_upon_load_error: options[:halt_upon_load_error],
  }

  command = if verify
    Commands::GemVerify.new(**command_args)
  elsif !gems.empty? || all
    Commands::GemGenerate.new(**command_args)
  else
    Commands::GemSync.new(**command_args)
  end

  command.run
end

#initObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tapioca/cli.rb', line 27

def init
  # We need to make sure that trackers stay enabled until the `gem` command is invoked
  Runtime::Trackers.with_trackers_enabled do
    invoke(:configure)
    invoke(:annotations)
    invoke(:gem)
  end

  # call the command directly to skip deprecation warning
  Commands::Todo.new(
    todo_file: DEFAULT_TODO_FILE,
    file_header: true,
  ).run

  print_init_next_steps
end

#requireObject



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

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

#todoObject



74
75
76
77
78
79
80
# File 'lib/tapioca/cli.rb', line 74

def todo
  command = Commands::Todo.new(
    todo_file: options[:todo_file],
    file_header: options[:file_header],
  )
  command.run_with_deprecation
end