Class: Tapioca::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/tapioca/cli.rb

Instance Method Summary collapse

Instance Method Details

#__print_versionObject


167
168
169
# File 'lib/tapioca/cli.rb', line 167

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

#dsl(*constants) ⇒ Object


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/tapioca/cli.rb', line 82

def dsl(*constants)
  current_command = T.must(current_command_chain.first)
  config = ConfigBuilder.from_options(current_command, options)
  generator = Generators::Dsl.new(
    requested_constants: constants,
    outpath: config.outpath,
    generators: config.generators,
    exclude_generators: config.exclude_generators,
    file_header: config.file_header,
    compiler_path: Tapioca::Compilers::Dsl::COMPILERS_PATH,
    tapioca_path: Config::TAPIOCA_PATH,
    default_command: Config::DEFAULT_COMMAND,
    should_verify: options[:verify],
    quiet: options[:quiet],
    verbose: options[:verbose]
  )
  Tapioca.silence_warnings do
    generator.generate
  end
end

#gem(*gems) ⇒ Object


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/tapioca/cli.rb', line 133

def gem(*gems)
  Tapioca.silence_warnings do
    all = options[:all]
    verify = options[:verify]
    current_command = T.must(current_command_chain.first)
    config = ConfigBuilder.from_options(current_command, options)
    generator = Generators::Gem.new(
      gem_names: all ? [] : gems,
      gem_excludes: config.exclude,
      prerequire: config.prerequire,
      postrequire: config.postrequire,
      typed_overrides: config.typed_overrides,
      default_command: Config::DEFAULT_COMMAND,
      outpath: config.outpath,
      file_header: config.file_header,
      doc: config.doc
    )

    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 gems.empty? && !all
      generator.sync(should_verify: verify)
    else
      generator.generate
    end
  end
end

#initObject


29
30
31
32
33
34
35
36
# File 'lib/tapioca/cli.rb', line 29

def init
  generator = Generators::Init.new(
    sorbet_config: Config::SORBET_CONFIG,
    default_postrequire: Config::DEFAULT_POSTREQUIRE,
    default_command: Config::DEFAULT_COMMAND
  )
  generator.generate
end

#requireObject


39
40
41
42
43
44
45
46
47
48
# File 'lib/tapioca/cli.rb', line 39

def require
  generator = Generators::Require.new(
    requires_path: ConfigBuilder.from_options(:require, options).postrequire,
    sorbet_config_path: Config::SORBET_CONFIG,
    default_command: Config::DEFAULT_COMMAND
  )
  Tapioca.silence_warnings do
    generator.generate
  end
end

#todoObject


51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tapioca/cli.rb', line 51

def todo
  current_command = T.must(current_command_chain.first)
  config = ConfigBuilder.from_options(current_command, options)
  generator = Generators::Todo.new(
    todos_path: config.todos_path,
    file_header: config.file_header,
    default_command: Config::DEFAULT_COMMAND
  )
  Tapioca.silence_warnings do
    generator.generate
  end
end