lib/tapioca/cli.rb in tapioca-0.11.8 vs lib/tapioca/cli.rb in tapioca-0.11.9

- old
+ new

@@ -21,47 +21,50 @@ aliases: ["-V"], type: :boolean, desc: "Verbose output for debugging purposes", default: false - desc "init", "get project ready for type checking" + desc "init", "Get project ready for type checking" 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 - invoke(:todo) + # 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 - desc "configure", "initialize folder structure and type checking configuration" + desc "configure", "Initialize folder structure and type checking configuration" option :postrequire, type: :string, default: DEFAULT_POSTREQUIRE_FILE def configure command = Commands::Configure.new( sorbet_config: SORBET_CONFIG_FILE, tapioca_config: options[:config], default_postrequire: options[:postrequire], ) - command.execute + command.run end - desc "require", "generate the list of files to be required by tapioca" + desc "require", "Generate the list of files to be required by tapioca" option :postrequire, type: :string, default: DEFAULT_POSTREQUIRE_FILE def require command = Commands::Require.new( requires_path: options[:postrequire], sorbet_config_path: SORBET_CONFIG_FILE, ) - Tapioca.silence_warnings do - command.execute - end + command.run end - desc "todo", "generate the list of unresolved constants" + desc "todo", "Generate the list of unresolved constants" option :todo_file, type: :string, desc: "Path to the generated todo RBI file", default: DEFAULT_TODO_FILE option :file_header, @@ -71,16 +74,14 @@ def todo command = Commands::Todo.new( todo_file: options[:todo_file], file_header: options[:file_header], ) - Tapioca.silence_warnings do - command.execute - end + command.run_with_deprecation end - desc "dsl [constant...]", "generate RBIs for dynamic methods" + desc "dsl [constant...]", "Generate RBIs for dynamic methods" option :outdir, aliases: ["--out", "-o"], banner: "directory", desc: "The output directory for generated DSL RBI files", default: DEFAULT_DSL_DIR @@ -138,37 +139,38 @@ 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 = Commands::Dsl.new( + 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, - should_verify: options[:verify], 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], - ) + } - Tapioca.silence_warnings do - if options[:list_compilers] - command.list_compilers - else - command.execute - end + 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 - desc "gem [gem...]", "generate RBIs from gems" + desc "gem [gem...]", "Generate RBIs from gems" option :outdir, aliases: ["--out", "-o"], banner: "directory", desc: "The output directory for generated gem RBI files", default: DEFAULT_GEM_DIR @@ -194,10 +196,14 @@ aliases: ["-x"], type: :array, banner: "gem [gem ...]", desc: "Exclude the given gem(s) from RBI generation", default: [] + option :include_dependencies, + type: :boolean, + desc: "Generate RBI files for dependencies of the given gem(s)", + default: false option :typed_overrides, aliases: ["--typed", "-t"], type: :hash, banner: "gem:level [gem:level ...]", desc: "Override for typed sigils for generated gem RBIs", @@ -243,51 +249,58 @@ option :halt_upon_load_error, type: :boolean, desc: "Halt upon a load error while loading the Rails application", default: true def gem(*gems) - Tapioca.silence_warnings do - set_environment(options) + set_environment(options) - all = options[:all] - verify = options[:verify] + all = options[:all] + verify = options[:verify] + include_dependencies = options[:include_dependencies] - 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), - halt_upon_load_error: options[:halt_upon_load_error], - ) + raise MalformattedArgumentError, "Options '--all' and '--verify' are mutually exclusive" if all && verify - 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 - 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 + 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], + } - if gems.empty? && !all - command.sync(should_verify: verify, exclude: options[:exclude]) - else - command.execute - end + 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 map "gems" => :gem - desc "check-shims", "check duplicated definitions in shim RBIs" + desc "check-shims", "Check duplicated definitions in shim RBIs" option :gem_rbi_dir, type: :string, desc: "Path to gem RBIs", default: DEFAULT_GEM_DIR option :dsl_rbi_dir, type: :string, desc: "Path to DSL RBIs", default: DEFAULT_DSL_DIR option :shim_rbi_dir, type: :string, desc: "Path to shim RBIs", default: DEFAULT_SHIM_DIR option :annotations_rbi_dir, type: :string, desc: "Path to annotations RBIs", default: DEFAULT_ANNOTATIONS_DIR option :todo_rbi_file, type: :string, desc: "Path to the generated todo RBI file", default: DEFAULT_TODO_FILE @@ -302,13 +315,11 @@ todo_rbi_file: options[:todo_rbi_file], payload: options[:payload], number_of_workers: options[:workers], ) - Tapioca.silence_warnings do - command.execute - end + command.run end desc "annotations", "Pull gem RBI annotations from remote sources" option :sources, type: :array, @@ -333,17 +344,15 @@ auth: options[:auth], netrc_file: netrc_file(options), typed_overrides: options[:typed_overrides], ) - Tapioca.silence_warnings do - command.execute - end + command.run end map ["--version", "-v"] => :__print_version - desc "--version, -v", "show version" + desc "--version, -v", "Show version" def __print_version puts "Tapioca v#{Tapioca::VERSION}" end no_commands do