Class: Tapioca::Cli
- Inherits:
-
Thor
- Object
- Thor
- Tapioca::Cli
- Includes:
- CliHelper, ConfigHelper
- 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
Instance Method Summary collapse
- #__print_version ⇒ Object
- #clean_shims(*files_to_clean) ⇒ Object
- #dsl(*constants) ⇒ Object
- #gem(*gems) ⇒ Object
- #init ⇒ Object
- #require ⇒ Object
- #todo ⇒ Object
Methods included from ConfigHelper
Methods included from CliHelper
Instance Method Details
#__print_version ⇒ Object
291 292 293 |
# File 'lib/tapioca/cli.rb', line 291 def __print_version puts "Tapioca v#{Tapioca::VERSION}" end |
#clean_shims(*files_to_clean) ⇒ Object
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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/tapioca/cli.rb', line 226 def clean_shims(*files_to_clean) index = RBI::Index.new # Index gem RBIs gem_rbi_dir = [:gem_rbi_dir] say("Loading gem RBIs from #{gem_rbi_dir}... ") gem_rbis_files = Dir.glob("#{gem_rbi_dir}/**/*.rbi").sort gem_rbis_trees = RBI::Parser.parse_files(gem_rbis_files) index.visit_all(gem_rbis_trees) say(" Done", :green) # Index dsl RBIs dsl_rbi_dir = [:dsl_rbi_dir] say("Loading dsl RBIs from #{dsl_rbi_dir}... ") dsl_rbis_files = Dir.glob("#{dsl_rbi_dir}/**/*.rbi").sort dsl_rbis_trees = RBI::Parser.parse_files(dsl_rbis_files) index.visit_all(dsl_rbis_trees) say(" Done", :green) # Clean shim RBIs if files_to_clean.empty? shim_rbi_dir = [:shim_rbi_dir] print("Cleaning shim RBIs from #{shim_rbi_dir}...") files_to_clean = Dir.glob("#{shim_rbi_dir}/*.rbi") else print("Cleaning shim RBIs...") end done_something = T.let(false, T::Boolean) files_to_clean.sort.each do |path| original = RBI::Parser.parse_file(path) cleaned, operations = RBI::Rewriters::RemoveKnownDefinitions.remove(original, index) next if operations.empty? done_something = true operations.each do |operation| print("\n #{operation}") end if cleaned.empty? print("\n Deleted empty file #{path}") FileUtils.rm(path) else File.write(path, cleaned.string) end end if done_something say("\nDone", :green) else say(" Done ", :green) say("(nothing to do)", :yellow) end rescue Errno::ENOENT => e say_error("\nCan't read RBI: #{e}") exit(1) rescue RBI::ParseError => e say_error("\nCan't parse RBI: #{e} (#{e.location})") exit(1) end |
#dsl(*constants) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/tapioca/cli.rb', line 100 def dsl(*constants) generator = Generators::Dsl.new( requested_constants: constants, outpath: Pathname.new([:outdir]), only: [:only], exclude: [:exclude], file_header: [:file_header], compiler_path: Tapioca::Compilers::Dsl::DSL_COMPILERS_DIR, tapioca_path: TAPIOCA_DIR, default_command: DEFAULT_COMMAND, should_verify: [:verify], quiet: [:quiet], verbose: [:verbose], number_of_workers: [:workers] ) if [:workers] != 1 say( "Using more than one worker is experimental and might produce results that are not deterministic", :red ) end Tapioca.silence_warnings do generator.generate end end |
#gem(*gems) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/tapioca/cli.rb', line 181 def gem(*gems) Tapioca.silence_warnings do all = [:all] verify = [:verify] generator = Generators::Gem.new( gem_names: all ? [] : gems, exclude: [:exclude], prerequire: [:prerequire], postrequire: [:postrequire], typed_overrides: [:typed_overrides], default_command: DEFAULT_COMMAND, outpath: Pathname.new([:outdir]), file_header: [:file_header], doc: [:doc], include_exported_rbis: [:exported_gem_rbis], number_of_workers: [:workers] ) 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 [:workers] != 1 say( "Using more than one worker is experimental and might produce results that are not deterministic", :red ) end if gems.empty? && !all generator.sync(should_verify: verify) else generator.generate end end end |
#init ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/tapioca/cli.rb', line 24 def init generator = Generators::Init.new( sorbet_config: SORBET_CONFIG_FILE, tapioca_config: TAPIOCA_CONFIG_FILE, default_postrequire: DEFAULT_POSTREQUIRE_FILE, default_command: DEFAULT_COMMAND ) generator.generate end |
#require ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tapioca/cli.rb', line 36 def require generator = Generators::Require.new( requires_path: [:postrequire], sorbet_config_path: SORBET_CONFIG_FILE, default_command: DEFAULT_COMMAND ) Tapioca.silence_warnings do generator.generate end end |
#todo ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tapioca/cli.rb', line 55 def todo generator = Generators::Todo.new( todo_file: [:todo_file], file_header: [:file_header], default_command: DEFAULT_COMMAND ) Tapioca.silence_warnings do generator.generate end end |