class Tapioca::Cli

Private Class Methods

exit_on_failure?() click to toggle source
# File lib/tapioca/cli.rb, line 250
def self.exit_on_failure?
  true
end

Public Instance Methods

__print_version() click to toggle source
# File lib/tapioca/cli.rb, line 211
def __print_version
  puts "Tapioca v#{Tapioca::VERSION}"
end
dsl(*constants) click to toggle source
# File lib/tapioca/cli.rb, line 69
def dsl(*constants)
  Tapioca.silence_warnings do
    generator.build_dsl(
      constants,
      should_verify: options[:verify],
      quiet: options[:quiet],
      verbose: options[:verbose]
    )
  end
end
gem(*gems) click to toggle source
# File lib/tapioca/cli.rb, line 107
def gem(*gems)
  Tapioca.silence_warnings do
    all = options[:all]
    verify = options[:verify]

    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_rbis_with_gemfile(should_verify: verify)
    else
      generator.build_gem_rbis(all ? [] : gems)
    end
  end
end
generate(*gems) click to toggle source
# File lib/tapioca/cli.rb, line 146
    def generate(*gems)
      gem_names = if gems.empty?
        "--all"
      else
        gems.join(" ")
      end
      deprecation_message = <<~MSG
        DEPRECATION: The `generate` command will be removed in a future release.

        Start using `bin/tapioca gem #{gem_names}` instead.
      MSG

      say(deprecation_message, :red)
      say("")

      Tapioca.silence_warnings do
        generator.build_gem_rbis(gems)
      end

      say("")
      say(deprecation_message, :red)
    end
init() click to toggle source
# File lib/tapioca/cli.rb, line 31
def init
  create_config
  create_post_require
  generate_binstub
end
require() click to toggle source
# File lib/tapioca/cli.rb, line 38
def require
  Tapioca.silence_warnings do
    generator.build_requires
  end
end
sync() click to toggle source
# File lib/tapioca/cli.rb, line 192
    def sync
      deprecation_message = <<~MSG
        DEPRECATION: The `sync` command will be removed in a future release.

        Start using `bin/tapioca gem` instead.
      MSG

      say(deprecation_message, :red)
      say("")

      Tapioca.silence_warnings do
        generator.sync_rbis_with_gemfile(should_verify: options[:verify])
      end

      say("")
      say(deprecation_message, :red)
    end
todo() click to toggle source
# File lib/tapioca/cli.rb, line 45
def todo
  Tapioca.silence_warnings do
    generator.build_todos
  end
end

Private Instance Methods

create_config() click to toggle source
# File lib/tapioca/cli.rb, line 217
    def create_config
      create_file(Config::SORBET_CONFIG, skip: true) do
        <<~CONTENT
          --dir
          .
        CONTENT
      end
    end
create_post_require() click to toggle source
# File lib/tapioca/cli.rb, line 226
    def create_post_require
      create_file(Config::DEFAULT_POSTREQUIRE, skip: true) do
        <<~CONTENT
          # typed: true
          # frozen_string_literal: true

          # Add your extra requires here (`tapioca require` can be used to boostrap this list)
        CONTENT
      end
    end
generate_binstub() click to toggle source
# File lib/tapioca/cli.rb, line 237
def generate_binstub
  bin_stub_exists = File.exist?("bin/tapioca")
  installer = Bundler::Installer.new(Bundler.root, Bundler.definition)
  spec = Bundler.definition.specs.find { |s| s.name == "tapioca" }
  installer.generate_bundler_executable_stubs(spec, { force: true })
  if bin_stub_exists
    shell.say_status(:force, "bin/tapioca", :yellow)
  else
    shell.say_status(:create, "bin/tapioca", :green)
  end
end
generator() click to toggle source
# File lib/tapioca/cli.rb, line 254
def generator
  current_command = T.must(current_command_chain.first)
  @generator ||= Generator.new(
    ConfigBuilder.from_options(current_command, options)
  )
end