class RBS::CLI

def run_validate(args, options)

def run_validate(args, options)
  OptionParser.new do |opts|
    opts.banner = <<EOU
e: rbs validate
date RBS files. It ensures the type names in RBS files are present and the type applications have correct arity.
ples:
rbs validate
    opts.on("--silent") do
      require "stringio"
      @stdout = StringIO.new
    end
  end.parse!(args)
  loader = options.loader()
  env = Environment.from_loader(loader).resolve_type_names
  builder = DefinitionBuilder.new(env: env)
  validator = Validator.new(env: env, resolver: TypeNameResolver.from_env(env))
  env.class_decls.each_key do |name|
    stdout.puts "Validating class/module definition: `#{name}`..."
    builder.build_instance(name).each_type do |type|
      validator.validate_type type, context: [Namespace.root]
    end
    builder.build_singleton(name).each_type do |type|
      validator.validate_type type, context: [Namespace.root]
    end
  end
  env.interface_decls.each_key do |name|
    stdout.puts "Validating interface: `#{name}`..."
    builder.build_interface(name).each_type do |type|
      validator.validate_type type, context: [Namespace.root]
    end
  end
  env.constant_decls.each do |name, const|
    stdout.puts "Validating constant: `#{name}`..."
    validator.validate_type const.decl.type, context: const.context
    builder.ensure_namespace!(name.namespace, location: const.decl.location)
  end
  env.global_decls.each do |name, global|
    stdout.puts "Validating global: `#{name}`..."
    validator.validate_type global.decl.type, context: [Namespace.root]
  end
  env.alias_decls.each do |name, decl|
    stdout.puts "Validating alias: `#{name}`..."
    builder.expand_alias(name).tap do |type|
      validator.validate_type type, context: [Namespace.root]
    end
    validator.validate_type_alias(entry: decl)
  end
end